using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Xml;
using ICSharpCode.TextEditor.Formatting.TSqlFormatter.Interfaces;

namespace ICSharpCode.TextEditor.Formatting.TSqlFormatter.Parsers
{
    public class TSqlStandardParser : ISqlTokenParser
    {
        public enum KeywordType
        {
            OperatorKeyword,
            FunctionKeyword,
            DataTypeKeyword,
            OtherKeyword
        }

        private static Regex _JoinDetector;

        private static Regex _CursorDetector;

        private static Regex _TriggerConditionDetector;

        public static Dictionary<string, KeywordType> KeywordList { get; set; }

        static TSqlStandardParser()
        {
            _JoinDetector = new Regex("^((RIGHT|INNER|LEFT|CROSS|FULL) )?(OUTER )?((HASH|LOOP|MERGE|REMOTE) )?(JOIN|APPLY) ");
            _CursorDetector = new Regex("^DECLARE [\\p{L}0-9_\\$\\@\\#]+ ((INSENSITIVE|SCROLL) ){0,2}CURSOR ");
            _TriggerConditionDetector = new Regex("^(FOR|AFTER|INSTEAD OF)( (INSERT|UPDATE|DELETE) (, (INSERT|UPDATE|DELETE) )?(, (INSERT|UPDATE|DELETE) )?)");
            InitializeKeywordList();
            KeywordList.Take(3);
        }

        public XmlDocument ParseSQL(ITokenList tokenList)
        {
            ParseTree parseTree = new ParseTree("SqlRoot");
            parseTree.StartNewStatement();
            int count = tokenList.Count;
            for (int i = 0; i < count; i++)
            {
                IToken token = tokenList[i];
                switch (token.Type)
                {
                    case SqlTokenType.OpenParens:
                        {
                            XmlElement firstNonWhitespaceNonCommentChildElement4 = parseTree.GetFirstNonWhitespaceNonCommentChildElement(parseTree.CurrentContainer);
                            XmlElement lastNonWhitespaceNonCommentChildElement = parseTree.GetLastNonWhitespaceNonCommentChildElement(parseTree.CurrentContainer);
                            bool flag11 = firstNonWhitespaceNonCommentChildElement4 != null && ((firstNonWhitespaceNonCommentChildElement4.Name.Equals("OtherKeyword") && firstNonWhitespaceNonCommentChildElement4.InnerText.ToUpperInvariant().StartsWith("INSERT")) || (firstNonWhitespaceNonCommentChildElement4.Name.Equals("CompoundKeyword") && firstNonWhitespaceNonCommentChildElement4.GetAttribute("simpleText").ToUpperInvariant().StartsWith("INSERT ")) || (firstNonWhitespaceNonCommentChildElement4.Name.Equals("OtherKeyword") && firstNonWhitespaceNonCommentChildElement4.InnerText.ToUpperInvariant().StartsWith("VALUES")));
                            if (parseTree.CurrentContainer.Name.Equals("CTEAlias") && parseTree.CurrentContainer.ParentNode.Name.Equals("CTEWithClause"))
                            {
                                parseTree.CurrentContainer = parseTree.SaveNewElement("DDLParens", "");
                            }
                            else if (parseTree.CurrentContainer.Name.Equals("ContainerContentBody") && parseTree.CurrentContainer.ParentNode.Name.Equals("CTEAsBlock"))
                            {
                                parseTree.CurrentContainer = parseTree.SaveNewElement("SelectionTargetParens", "");
                            }
                            else if (firstNonWhitespaceNonCommentChildElement4 == null && parseTree.CurrentContainer.Name.Equals("SelectionTarget"))
                            {
                                parseTree.CurrentContainer = parseTree.SaveNewElement("SelectionTargetParens", "");
                            }
                            else if (firstNonWhitespaceNonCommentChildElement4 != null && firstNonWhitespaceNonCommentChildElement4.Name.Equals("SetOperatorClause"))
                            {
                                parseTree.ConsiderStartingNewClause();
                                parseTree.CurrentContainer = parseTree.SaveNewElement("SelectionTargetParens", "");
                            }
                            else if (IsLatestTokenADDLDetailValue(parseTree))
                            {
                                parseTree.CurrentContainer = parseTree.SaveNewElement("DDLDetailParens", "");
                            }
                            else if (parseTree.CurrentContainer.Name.Equals("DDLProceduralBlock") || parseTree.CurrentContainer.Name.Equals("DDLOtherBlock") || parseTree.CurrentContainer.Name.Equals("DDLDeclareBlock") || (parseTree.CurrentContainer.Name.Equals("Clause") && firstNonWhitespaceNonCommentChildElement4 != null && firstNonWhitespaceNonCommentChildElement4.Name.Equals("OtherKeyword") && firstNonWhitespaceNonCommentChildElement4.InnerText.ToUpperInvariant().StartsWith("OPTION")) || flag11)
                            {
                                parseTree.CurrentContainer = parseTree.SaveNewElement("DDLParens", "");
                            }
                            else if (lastNonWhitespaceNonCommentChildElement != null && lastNonWhitespaceNonCommentChildElement.Name.Equals("AlphaOperator") && lastNonWhitespaceNonCommentChildElement.InnerText.ToUpperInvariant().Equals("IN"))
                            {
                                parseTree.CurrentContainer = parseTree.SaveNewElement("InParens", "");
                            }
                            else if (IsLatestTokenAMiscName(parseTree.CurrentContainer))
                            {
                                parseTree.CurrentContainer = parseTree.SaveNewElement("FunctionParens", "");
                            }
                            else
                            {
                                parseTree.CurrentContainer = parseTree.SaveNewElement("ExpressionParens", "");
                            }
                            break;
                        }
                    case SqlTokenType.CloseParens:
                        parseTree.EscapeAnySingleOrPartialStatementContainers();
                        if (parseTree.CurrentContainer.Name.Equals("DDLDetailParens") || parseTree.CurrentContainer.Name.Equals("DDLParens") || parseTree.CurrentContainer.Name.Equals("FunctionParens") || parseTree.CurrentContainer.Name.Equals("InParens") || parseTree.CurrentContainer.Name.Equals("ExpressionParens") || parseTree.CurrentContainer.Name.Equals("SelectionTargetParens"))
                        {
                            parseTree.MoveToAncestorContainer(1);
                        }
                        else if (parseTree.CurrentContainer.Name.Equals("Clause") && parseTree.CurrentContainer.ParentNode.Name.Equals("SelectionTargetParens") && parseTree.CurrentContainer.ParentNode.ParentNode.Name.Equals("ContainerContentBody") && parseTree.CurrentContainer.ParentNode.ParentNode.ParentNode.Name.Equals("CTEAsBlock"))
                        {
                            parseTree.MoveToAncestorContainer(4, "CTEWithClause");
                            parseTree.CurrentContainer = parseTree.SaveNewElement("ContainerContentBody", "");
                        }
                        else if (parseTree.CurrentContainer.Name.Equals("Clause") && (parseTree.CurrentContainer.ParentNode.Name.Equals("ExpressionParens") || parseTree.CurrentContainer.ParentNode.Name.Equals("InParens") || parseTree.CurrentContainer.ParentNode.Name.Equals("SelectionTargetParens")))
                        {
                            parseTree.MoveToAncestorContainer(2);
                        }
                        else
                        {
                            parseTree.SaveNewElementWithError("Other", ")");
                        }
                        break;
                    case SqlTokenType.OtherNode:
                        {
                            List<int> significantTokenPositions = GetSignificantTokenPositions(tokenList, i, 7);
                            string text = ExtractTokensString(tokenList, significantTokenPositions);
                            if (parseTree.PathNameMatches(0, "PermissionsDetail"))
                            {
                                if (text.StartsWith("ON "))
                                {
                                    parseTree.MoveToAncestorContainer(1, "PermissionsBlock");
                                    parseTree.StartNewContainer("PermissionsTarget", token.Value, "ContainerContentBody");
                                }
                                else if (text.StartsWith("TO ") || text.StartsWith("FROM "))
                                {
                                    parseTree.MoveToAncestorContainer(1, "PermissionsBlock");
                                    parseTree.StartNewContainer("PermissionsRecipient", token.Value, "ContainerContentBody");
                                }
                                else
                                {
                                    parseTree.SaveNewElement("OtherKeyword", token.Value);
                                }
                                break;
                            }
                            if (text.StartsWith("CREATE PROC") || text.StartsWith("CREATE FUNC") || text.StartsWith("CREATE TRIGGER ") || text.StartsWith("CREATE VIEW ") || text.StartsWith("ALTER PROC") || text.StartsWith("ALTER FUNC") || text.StartsWith("ALTER TRIGGER ") || text.StartsWith("ALTER VIEW "))
                            {
                                parseTree.ConsiderStartingNewStatement();
                                parseTree.CurrentContainer = parseTree.SaveNewElement("DDLProceduralBlock", "");
                                parseTree.SaveNewElement("OtherKeyword", token.Value);
                                break;
                            }
                            if (_CursorDetector.IsMatch(text))
                            {
                                parseTree.ConsiderStartingNewStatement();
                                parseTree.CurrentContainer = parseTree.SaveNewElement("CursorDeclaration", "");
                                parseTree.SaveNewElement("OtherKeyword", token.Value);
                                break;
                            }
                            if (parseTree.PathNameMatches(0, "DDLProceduralBlock") && _TriggerConditionDetector.IsMatch(text))
                            {
                                Match match = _TriggerConditionDetector.Match(text);
                                parseTree.CurrentContainer = parseTree.SaveNewElement("TriggerCondition", "");
                                XmlElement xmlElement = parseTree.SaveNewElement("CompoundKeyword", "");
                                string value = match.Groups[1].Value;
                                xmlElement.SetAttribute("simpleText", value);
                                int num = value.Split(' ').Length;
                                AppendNodesWithMapping(parseTree, tokenList.GetRangeByIndex(significantTokenPositions[0], significantTokenPositions[num - 1]), "OtherKeyword", xmlElement);
                                int num2 = match.Groups[2].Value.Split(' ').Length - 2;
                                AppendNodesWithMapping(parseTree, tokenList.GetRangeByIndex(significantTokenPositions[num - 1] + 1, significantTokenPositions[num + num2 - 1]), "OtherKeyword", parseTree.CurrentContainer);
                                i = significantTokenPositions[num + num2 - 1];
                                parseTree.MoveToAncestorContainer(1, "DDLProceduralBlock");
                                break;
                            }
                            if (text.StartsWith("FOR "))
                            {
                                parseTree.EscapeAnyBetweenConditions();
                                parseTree.EscapeAnySelectionTarget();
                                parseTree.EscapeJoinCondition();
                                if (parseTree.PathNameMatches(0, "CursorDeclaration"))
                                {
                                    parseTree.StartNewContainer("CursorForBlock", token.Value, "ContainerContentBody");
                                    parseTree.StartNewStatement();
                                }
                                else if (parseTree.PathNameMatches(0, "Clause") && parseTree.PathNameMatches(1, "SqlStatement") && parseTree.PathNameMatches(2, "ContainerContentBody") && parseTree.PathNameMatches(3, "CursorForBlock"))
                                {
                                    parseTree.MoveToAncestorContainer(4, "CursorDeclaration");
                                    parseTree.StartNewContainer("CursorForOptions", token.Value, "ContainerContentBody");
                                }
                                else
                                {
                                    parseTree.ConsiderStartingNewClause();
                                    parseTree.SaveNewElement("OtherKeyword", token.Value);
                                }
                                break;
                            }
                            if (text.StartsWith("DECLARE "))
                            {
                                parseTree.ConsiderStartingNewStatement();
                                parseTree.CurrentContainer = parseTree.SaveNewElement("DDLDeclareBlock", "");
                                parseTree.SaveNewElement("OtherKeyword", token.Value);
                                break;
                            }
                            if (text.StartsWith("CREATE ") || text.StartsWith("ALTER "))
                            {
                                parseTree.ConsiderStartingNewStatement();
                                parseTree.CurrentContainer = parseTree.SaveNewElement("DDLOtherBlock", "");
                                parseTree.SaveNewElement("OtherKeyword", token.Value);
                                break;
                            }
                            if (text.StartsWith("GRANT ") || text.StartsWith("DENY ") || text.StartsWith("REVOKE "))
                            {
                                if (text.StartsWith("GRANT ") && parseTree.PathNameMatches(0, "ContainerContentBody") && parseTree.PathNameMatches(1, "DDLWith") && parseTree.PathNameMatches(2, "PermissionsBlock") && parseTree.GetFirstNonWhitespaceNonCommentChildElement(parseTree.CurrentContainer) == null)
                                {
                                    parseTree.SaveNewElement("OtherKeyword", token.Value);
                                    break;
                                }
                                parseTree.ConsiderStartingNewStatement();
                                parseTree.StartNewContainer("PermissionsBlock", token.Value, "PermissionsDetail");
                                break;
                            }
                            if (parseTree.CurrentContainer.Name.Equals("DDLProceduralBlock") && text.StartsWith("RETURNS "))
                            {
                                parseTree.SaveNewElement("OtherKeyword", token.Value, parseTree.SaveNewElement("DDLReturns", ""));
                                break;
                            }
                            if (text.StartsWith("AS "))
                            {
                                if (parseTree.PathNameMatches(0, "DDLProceduralBlock"))
                                {
                                    bool flag = false;
                                    if (significantTokenPositions.Count > 1 && KeywordList.TryGetValue(tokenList[significantTokenPositions[1]].Value, out var value2) && value2 == KeywordType.DataTypeKeyword)
                                    {
                                        flag = true;
                                    }
                                    if (flag)
                                    {
                                        parseTree.SaveNewElement("OtherKeyword", token.Value);
                                        break;
                                    }
                                    parseTree.StartNewContainer("DDLAsBlock", token.Value, "ContainerContentBody");
                                    parseTree.StartNewStatement();
                                }
                                else if (parseTree.PathNameMatches(0, "ContainerContentBody") && parseTree.PathNameMatches(1, "DDLWith") && parseTree.PathNameMatches(2, "DDLProceduralBlock"))
                                {
                                    parseTree.MoveToAncestorContainer(2, "DDLProceduralBlock");
                                    parseTree.StartNewContainer("DDLAsBlock", token.Value, "ContainerContentBody");
                                    parseTree.StartNewStatement();
                                }
                                else if (parseTree.PathNameMatches(0, "CTEAlias") && parseTree.PathNameMatches(1, "CTEWithClause"))
                                {
                                    parseTree.MoveToAncestorContainer(1, "CTEWithClause");
                                    parseTree.StartNewContainer("CTEAsBlock", token.Value, "ContainerContentBody");
                                }
                                else
                                {
                                    parseTree.SaveNewElement("OtherKeyword", token.Value);
                                }
                                break;
                            }
                            if (text.StartsWith("BEGIN DISTRIBUTED TRANSACTION ") || text.StartsWith("BEGIN DISTRIBUTED TRAN "))
                            {
                                parseTree.ConsiderStartingNewStatement();
                                ProcessCompoundKeyword(tokenList, parseTree, parseTree.SaveNewElement("BeginTransaction", ""), ref i, significantTokenPositions, 3);
                                break;
                            }
                            if (text.StartsWith("BEGIN TRANSACTION ") || text.StartsWith("BEGIN TRAN "))
                            {
                                parseTree.ConsiderStartingNewStatement();
                                ProcessCompoundKeyword(tokenList, parseTree, parseTree.SaveNewElement("BeginTransaction", ""), ref i, significantTokenPositions, 2);
                                break;
                            }
                            if (text.StartsWith("SAVE TRANSACTION ") || text.StartsWith("SAVE TRAN "))
                            {
                                parseTree.ConsiderStartingNewStatement();
                                ProcessCompoundKeyword(tokenList, parseTree, parseTree.SaveNewElement("SaveTransaction", ""), ref i, significantTokenPositions, 2);
                                break;
                            }
                            if (text.StartsWith("COMMIT TRANSACTION ") || text.StartsWith("COMMIT TRAN ") || text.StartsWith("COMMIT WORK "))
                            {
                                parseTree.ConsiderStartingNewStatement();
                                ProcessCompoundKeyword(tokenList, parseTree, parseTree.SaveNewElement("CommitTransaction", ""), ref i, significantTokenPositions, 2);
                                break;
                            }
                            if (text.StartsWith("COMMIT "))
                            {
                                parseTree.ConsiderStartingNewStatement();
                                parseTree.SaveNewElement("OtherKeyword", token.Value, parseTree.SaveNewElement("CommitTransaction", token.Value));
                                break;
                            }
                            if (text.StartsWith("ROLLBACK TRANSACTION ") || text.StartsWith("ROLLBACK TRAN ") || text.StartsWith("ROLLBACK WORK "))
                            {
                                parseTree.ConsiderStartingNewStatement();
                                ProcessCompoundKeyword(tokenList, parseTree, parseTree.SaveNewElement("RollbackTransaction", ""), ref i, significantTokenPositions, 2);
                                break;
                            }
                            if (text.StartsWith("ROLLBACK "))
                            {
                                parseTree.ConsiderStartingNewStatement();
                                parseTree.SaveNewElement("OtherKeyword", token.Value, parseTree.SaveNewElement("RollbackTransaction", token.Value));
                                break;
                            }
                            if (text.StartsWith("BEGIN TRY "))
                            {
                                parseTree.ConsiderStartingNewStatement();
                                XmlElement targetNode = parseTree.SaveNewElement("TryBlock", "");
                                XmlElement targetContainer = parseTree.SaveNewElement("ContainerOpen", "", targetNode);
                                ProcessCompoundKeyword(tokenList, parseTree, targetContainer, ref i, significantTokenPositions, 2);
                                XmlElement targetNode2 = parseTree.SaveNewElement("ContainerMultiStatementBody", "", targetNode);
                                parseTree.StartNewStatement(targetNode2);
                                break;
                            }
                            if (text.StartsWith("BEGIN CATCH "))
                            {
                                parseTree.ConsiderStartingNewStatement();
                                XmlElement targetNode3 = parseTree.SaveNewElement("CatchBlock", "");
                                XmlElement targetContainer2 = parseTree.SaveNewElement("ContainerOpen", "", targetNode3);
                                ProcessCompoundKeyword(tokenList, parseTree, targetContainer2, ref i, significantTokenPositions, 2);
                                XmlElement targetNode4 = parseTree.SaveNewElement("ContainerMultiStatementBody", "", targetNode3);
                                parseTree.StartNewStatement(targetNode4);
                                break;
                            }
                            if (text.StartsWith("BEGIN "))
                            {
                                parseTree.ConsiderStartingNewStatement();
                                parseTree.StartNewContainer("BeginEndBlock", token.Value, "ContainerMultiStatementBody");
                                parseTree.StartNewStatement();
                                break;
                            }
                            if (text.StartsWith("MERGE "))
                            {
                                parseTree.ConsiderStartingNewStatement();
                                parseTree.ConsiderStartingNewClause();
                                parseTree.StartNewContainer("MergeClause", token.Value, "MergeTarget");
                                break;
                            }
                            if (text.StartsWith("USING "))
                            {
                                if (parseTree.PathNameMatches(0, "MergeTarget"))
                                {
                                    parseTree.MoveToAncestorContainer(1, "MergeClause");
                                    parseTree.StartNewContainer("MergeUsing", token.Value, "SelectionTarget");
                                }
                                else
                                {
                                    parseTree.SaveNewElementWithError("Other", token.Value);
                                }
                                break;
                            }
                            if (text.StartsWith("ON "))
                            {
                                parseTree.EscapeAnySelectionTarget();
                                if (parseTree.PathNameMatches(0, "MergeUsing"))
                                {
                                    parseTree.MoveToAncestorContainer(1, "MergeClause");
                                    parseTree.StartNewContainer("MergeCondition", token.Value, "ContainerContentBody");
                                }
                                else if (!parseTree.PathNameMatches(0, "DDLProceduralBlock") && !parseTree.PathNameMatches(0, "DDLOtherBlock") && !parseTree.PathNameMatches(1, "DDLWith") && !parseTree.PathNameMatches(0, "ExpressionParens") && !ContentStartsWithKeyword(parseTree.CurrentContainer, "SET"))
                                {
                                    parseTree.StartNewContainer("JoinOn", token.Value, "ContainerContentBody");
                                }
                                else
                                {
                                    parseTree.SaveNewElement("OtherKeyword", token.Value);
                                }
                                break;
                            }
                            if (text.StartsWith("CASE "))
                            {
                                parseTree.StartNewContainer("CaseStatement", token.Value, "Input");
                                break;
                            }
                            if (text.StartsWith("WHEN "))
                            {
                                parseTree.EscapeMergeAction();
                                if (parseTree.PathNameMatches(0, "Input") || (parseTree.PathNameMatches(0, "ContainerContentBody") && parseTree.PathNameMatches(1, "Then")))
                                {
                                    if (parseTree.PathNameMatches(0, "Input"))
                                    {
                                        parseTree.MoveToAncestorContainer(1, "CaseStatement");
                                    }
                                    else
                                    {
                                        parseTree.MoveToAncestorContainer(3, "CaseStatement");
                                    }
                                    parseTree.StartNewContainer("When", token.Value, "ContainerContentBody");
                                }
                                else if ((parseTree.PathNameMatches(0, "ContainerContentBody") && parseTree.PathNameMatches(1, "MergeCondition")) || parseTree.PathNameMatches(0, "MergeWhen"))
                                {
                                    if (parseTree.PathNameMatches(1, "MergeCondition"))
                                    {
                                        parseTree.MoveToAncestorContainer(2, "MergeClause");
                                    }
                                    else
                                    {
                                        parseTree.MoveToAncestorContainer(1, "MergeClause");
                                    }
                                    parseTree.StartNewContainer("MergeWhen", token.Value, "ContainerContentBody");
                                }
                                else
                                {
                                    parseTree.SaveNewElementWithError("Other", token.Value);
                                }
                                break;
                            }
                            if (text.StartsWith("THEN "))
                            {
                                parseTree.EscapeAnyBetweenConditions();
                                if (parseTree.PathNameMatches(0, "ContainerContentBody") && parseTree.PathNameMatches(1, "When"))
                                {
                                    parseTree.MoveToAncestorContainer(1, "When");
                                    parseTree.StartNewContainer("Then", token.Value, "ContainerContentBody");
                                }
                                else if (parseTree.PathNameMatches(0, "ContainerContentBody") && parseTree.PathNameMatches(1, "MergeWhen"))
                                {
                                    parseTree.MoveToAncestorContainer(1, "MergeWhen");
                                    parseTree.StartNewContainer("MergeThen", token.Value, "MergeAction");
                                    parseTree.StartNewStatement();
                                }
                                else
                                {
                                    parseTree.SaveNewElementWithError("Other", token.Value);
                                }
                                break;
                            }
                            if (text.StartsWith("OUTPUT "))
                            {
                                bool flag2 = false;
                                if (parseTree.PathNameMatches(0, "Clause") && parseTree.PathNameMatches(1, "SqlStatement") && (ContentStartsWithKeyword(parseTree.CurrentContainer, "EXEC") || ContentStartsWithKeyword(parseTree.CurrentContainer, "EXECUTE") || ContentStartsWithKeyword(parseTree.CurrentContainer, null)))
                                {
                                    flag2 = true;
                                }
                                if (parseTree.PathNameMatches(0, "DDLProceduralBlock"))
                                {
                                    flag2 = true;
                                }
                                if (!flag2)
                                {
                                    parseTree.EscapeMergeAction();
                                    parseTree.ConsiderStartingNewClause();
                                }
                                parseTree.SaveNewElement("OtherKeyword", token.Value);
                                break;
                            }
                            if (text.StartsWith("OPTION "))
                            {
                                if (!parseTree.PathNameMatches(0, "ContainerContentBody") || !parseTree.PathNameMatches(1, "DDLWith"))
                                {
                                    parseTree.EscapeMergeAction();
                                    parseTree.ConsiderStartingNewClause();
                                }
                                parseTree.SaveNewElement("OtherKeyword", token.Value);
                                break;
                            }
                            if (text.StartsWith("END TRY "))
                            {
                                parseTree.EscapeAnySingleOrPartialStatementContainers();
                                if (parseTree.PathNameMatches(0, "Clause") && parseTree.PathNameMatches(1, "SqlStatement") && parseTree.PathNameMatches(2, "ContainerMultiStatementBody") && parseTree.PathNameMatches(3, "TryBlock"))
                                {
                                    XmlElement xmlElement2 = (XmlElement)parseTree.CurrentContainer.ParentNode.ParentNode.ParentNode;
                                    XmlElement targetContainer3 = parseTree.SaveNewElement("ContainerClose", "", xmlElement2);
                                    ProcessCompoundKeyword(tokenList, parseTree, targetContainer3, ref i, significantTokenPositions, 2);
                                    parseTree.CurrentContainer = (XmlElement)xmlElement2.ParentNode;
                                }
                                else
                                {
                                    ProcessCompoundKeywordWithError(tokenList, parseTree, parseTree.CurrentContainer, ref i, significantTokenPositions, 2);
                                }
                                break;
                            }
                            if (text.StartsWith("END CATCH "))
                            {
                                parseTree.EscapeAnySingleOrPartialStatementContainers();
                                if (parseTree.PathNameMatches(0, "Clause") && parseTree.PathNameMatches(1, "SqlStatement") && parseTree.PathNameMatches(2, "ContainerMultiStatementBody") && parseTree.PathNameMatches(3, "CatchBlock"))
                                {
                                    XmlElement xmlElement3 = (XmlElement)parseTree.CurrentContainer.ParentNode.ParentNode.ParentNode;
                                    XmlElement targetContainer4 = parseTree.SaveNewElement("ContainerClose", "", xmlElement3);
                                    ProcessCompoundKeyword(tokenList, parseTree, targetContainer4, ref i, significantTokenPositions, 2);
                                    parseTree.CurrentContainer = (XmlElement)xmlElement3.ParentNode;
                                }
                                else
                                {
                                    ProcessCompoundKeywordWithError(tokenList, parseTree, parseTree.CurrentContainer, ref i, significantTokenPositions, 2);
                                }
                                break;
                            }
                            if (text.StartsWith("END "))
                            {
                                if (parseTree.PathNameMatches(0, "ContainerContentBody") && parseTree.PathNameMatches(1, "Then"))
                                {
                                    parseTree.MoveToAncestorContainer(3, "CaseStatement");
                                    parseTree.SaveNewElement("OtherKeyword", token.Value, parseTree.SaveNewElement("ContainerClose", ""));
                                    parseTree.MoveToAncestorContainer(1);
                                    break;
                                }
                                if (parseTree.PathNameMatches(0, "ContainerContentBody") && parseTree.PathNameMatches(1, "CaseElse"))
                                {
                                    parseTree.MoveToAncestorContainer(2, "CaseStatement");
                                    parseTree.SaveNewElement("OtherKeyword", token.Value, parseTree.SaveNewElement("ContainerClose", ""));
                                    parseTree.MoveToAncestorContainer(1);
                                    break;
                                }
                                parseTree.EscapeAnySingleOrPartialStatementContainers();
                                if (parseTree.PathNameMatches(0, "Clause") && parseTree.PathNameMatches(1, "SqlStatement") && parseTree.PathNameMatches(2, "ContainerMultiStatementBody") && parseTree.PathNameMatches(3, "BeginEndBlock"))
                                {
                                    XmlElement xmlElement4 = (XmlElement)parseTree.CurrentContainer.ParentNode.ParentNode.ParentNode;
                                    XmlElement targetNode5 = parseTree.SaveNewElement("ContainerClose", "", xmlElement4);
                                    parseTree.SaveNewElement("OtherKeyword", token.Value, targetNode5);
                                    parseTree.CurrentContainer = (XmlElement)xmlElement4.ParentNode;
                                }
                                else
                                {
                                    parseTree.SaveNewElementWithError("OtherKeyword", token.Value);
                                }
                                break;
                            }
                            if (text.StartsWith("GO "))
                            {
                                parseTree.EscapeAnySingleOrPartialStatementContainers();
                                if ((i == 0 || IsLineBreakingWhiteSpaceOrComment(tokenList[i - 1])) && IsFollowedByLineBreakingWhiteSpaceOrSingleLineCommentOrEnd(tokenList, i))
                                {
                                    if (parseTree.FindValidBatchEnd())
                                    {
                                        XmlElement documentElement = parseTree.DocumentElement;
                                        XmlElement targetNode6 = parseTree.SaveNewElement("BatchSeparator", "", documentElement);
                                        parseTree.SaveNewElement("OtherKeyword", token.Value, targetNode6);
                                        parseTree.StartNewStatement(documentElement);
                                    }
                                    else
                                    {
                                        parseTree.SaveNewElementWithError("OtherKeyword", token.Value);
                                    }
                                }
                                else
                                {
                                    parseTree.SaveNewElement("OtherKeyword", token.Value);
                                }
                                break;
                            }
                            if (text.StartsWith("EXECUTE AS "))
                            {
                                bool flag3 = false;
                                if (parseTree.PathNameMatches(0, "ContainerContentBody") && parseTree.PathNameMatches(1, "DDLWith") && (IsLatestTokenAComma(parseTree) || !parseTree.HasNonWhiteSpaceNonCommentContent(parseTree.CurrentContainer)))
                                {
                                    flag3 = true;
                                }
                                if (!flag3)
                                {
                                    parseTree.ConsiderStartingNewStatement();
                                    parseTree.ConsiderStartingNewClause();
                                }
                                ProcessCompoundKeyword(tokenList, parseTree, parseTree.CurrentContainer, ref i, significantTokenPositions, 2);
                                break;
                            }
                            if (text.StartsWith("EXEC ") || text.StartsWith("EXECUTE "))
                            {
                                bool flag4 = false;
                                if (parseTree.PathNameMatches(0, "Clause") && parseTree.PathNameMatches(1, "SqlStatement") && (ContentStartsWithKeyword(parseTree.CurrentContainer, "INSERT") || ContentStartsWithKeyword(parseTree.CurrentContainer, "INSERT INTO")))
                                {
                                    int count2 = parseTree.CurrentContainer.SelectNodes(string.Format("../{0}", "Clause")).Count;
                                    if (count2 == 1)
                                    {
                                        flag4 = true;
                                    }
                                }
                                if (!flag4)
                                {
                                    parseTree.ConsiderStartingNewStatement();
                                }
                                parseTree.ConsiderStartingNewClause();
                                parseTree.SaveNewElement("OtherKeyword", token.Value);
                                break;
                            }
                            if (_JoinDetector.IsMatch(text))
                            {
                                parseTree.ConsiderStartingNewClause();
                                string value3 = _JoinDetector.Match(text).Value;
                                int keywordCount = value3.Split(new char[1] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Length;
                                ProcessCompoundKeyword(tokenList, parseTree, parseTree.CurrentContainer, ref i, significantTokenPositions, keywordCount);
                                parseTree.CurrentContainer = parseTree.SaveNewElement("SelectionTarget", "");
                                break;
                            }
                            if (text.StartsWith("UNION ALL "))
                            {
                                parseTree.ConsiderStartingNewClause();
                                ProcessCompoundKeyword(tokenList, parseTree, parseTree.SaveNewElement("SetOperatorClause", ""), ref i, significantTokenPositions, 2);
                                break;
                            }
                            if (text.StartsWith("UNION ") || text.StartsWith("INTERSECT ") || text.StartsWith("EXCEPT "))
                            {
                                parseTree.ConsiderStartingNewClause();
                                XmlElement targetNode7 = parseTree.SaveNewElement("SetOperatorClause", "");
                                parseTree.SaveNewElement("OtherKeyword", token.Value, targetNode7);
                                break;
                            }
                            if (text.StartsWith("WHILE "))
                            {
                                parseTree.ConsiderStartingNewStatement();
                                XmlElement targetNode8 = parseTree.SaveNewElement("WhileLoop", "");
                                XmlElement targetNode9 = parseTree.SaveNewElement("ContainerOpen", "", targetNode8);
                                parseTree.SaveNewElement("OtherKeyword", token.Value, targetNode9);
                                parseTree.CurrentContainer = parseTree.SaveNewElement("BooleanExpression", "", targetNode8);
                                break;
                            }
                            if (text.StartsWith("IF "))
                            {
                                parseTree.ConsiderStartingNewStatement();
                                parseTree.StartNewContainer("IfStatement", token.Value, "BooleanExpression");
                                break;
                            }
                            if (text.StartsWith("ELSE "))
                            {
                                parseTree.EscapeAnyBetweenConditions();
                                parseTree.EscapeAnySelectionTarget();
                                parseTree.EscapeJoinCondition();
                                if (parseTree.PathNameMatches(0, "ContainerContentBody") && parseTree.PathNameMatches(1, "Then"))
                                {
                                    parseTree.MoveToAncestorContainer(3, "CaseStatement");
                                    parseTree.StartNewContainer("CaseElse", token.Value, "ContainerContentBody");
                                    break;
                                }
                                parseTree.EscapePartialStatementContainers();
                                if (parseTree.PathNameMatches(0, "Clause") && parseTree.PathNameMatches(1, "SqlStatement") && parseTree.PathNameMatches(2, "ContainerSingleStatementBody"))
                                {
                                    XmlElement xmlElement5 = (XmlElement)parseTree.CurrentContainer.ParentNode.ParentNode;
                                    bool flag5 = false;
                                    while (!flag5)
                                    {
                                        if (parseTree.PathNameMatches(xmlElement5, 1, "IfStatement"))
                                        {
                                            parseTree.CurrentContainer = (XmlElement)xmlElement5.ParentNode;
                                            parseTree.StartNewContainer("ElseClause", token.Value, "ContainerSingleStatementBody");
                                            parseTree.StartNewStatement();
                                            flag5 = true;
                                        }
                                        else if (parseTree.PathNameMatches(xmlElement5, 1, "ElseClause"))
                                        {
                                            xmlElement5 = (XmlElement)xmlElement5.ParentNode.ParentNode.ParentNode.ParentNode.ParentNode;
                                        }
                                        else if (parseTree.PathNameMatches(xmlElement5, 1, "WhileLoop"))
                                        {
                                            xmlElement5 = (XmlElement)xmlElement5.ParentNode.ParentNode.ParentNode.ParentNode;
                                        }
                                        else
                                        {
                                            parseTree.SaveNewElementWithError("OtherKeyword", token.Value);
                                            flag5 = true;
                                        }
                                    }
                                }
                                else
                                {
                                    parseTree.SaveNewElementWithError("OtherKeyword", token.Value);
                                }
                                break;
                            }
                            if (text.StartsWith("INSERT INTO "))
                            {
                                parseTree.ConsiderStartingNewStatement();
                                parseTree.ConsiderStartingNewClause();
                                ProcessCompoundKeyword(tokenList, parseTree, parseTree.CurrentContainer, ref i, significantTokenPositions, 2);
                                break;
                            }
                            if (text.StartsWith("NATIONAL CHARACTER VARYING "))
                            {
                                ProcessCompoundKeyword(tokenList, parseTree, parseTree.CurrentContainer, ref i, significantTokenPositions, 3);
                                break;
                            }
                            if (text.StartsWith("NATIONAL CHAR VARYING "))
                            {
                                ProcessCompoundKeyword(tokenList, parseTree, parseTree.CurrentContainer, ref i, significantTokenPositions, 3);
                                break;
                            }
                            if (text.StartsWith("BINARY VARYING "))
                            {
                                ProcessCompoundKeyword(tokenList, parseTree, parseTree.CurrentContainer, ref i, significantTokenPositions, 2);
                                break;
                            }
                            if (text.StartsWith("CHAR VARYING "))
                            {
                                ProcessCompoundKeyword(tokenList, parseTree, parseTree.CurrentContainer, ref i, significantTokenPositions, 2);
                                break;
                            }
                            if (text.StartsWith("CHARACTER VARYING "))
                            {
                                ProcessCompoundKeyword(tokenList, parseTree, parseTree.CurrentContainer, ref i, significantTokenPositions, 2);
                                break;
                            }
                            if (text.StartsWith("DOUBLE PRECISION "))
                            {
                                ProcessCompoundKeyword(tokenList, parseTree, parseTree.CurrentContainer, ref i, significantTokenPositions, 2);
                                break;
                            }
                            if (text.StartsWith("NATIONAL CHARACTER "))
                            {
                                ProcessCompoundKeyword(tokenList, parseTree, parseTree.CurrentContainer, ref i, significantTokenPositions, 2);
                                break;
                            }
                            if (text.StartsWith("NATIONAL CHAR "))
                            {
                                ProcessCompoundKeyword(tokenList, parseTree, parseTree.CurrentContainer, ref i, significantTokenPositions, 2);
                                break;
                            }
                            if (text.StartsWith("NATIONAL TEXT "))
                            {
                                ProcessCompoundKeyword(tokenList, parseTree, parseTree.CurrentContainer, ref i, significantTokenPositions, 2);
                                break;
                            }
                            if (text.StartsWith("INSERT "))
                            {
                                parseTree.ConsiderStartingNewStatement();
                                parseTree.ConsiderStartingNewClause();
                                parseTree.SaveNewElement("OtherKeyword", token.Value);
                                break;
                            }
                            if (text.StartsWith("BULK INSERT "))
                            {
                                parseTree.ConsiderStartingNewStatement();
                                parseTree.ConsiderStartingNewClause();
                                ProcessCompoundKeyword(tokenList, parseTree, parseTree.CurrentContainer, ref i, significantTokenPositions, 2);
                                break;
                            }
                            if (text.StartsWith("SELECT "))
                            {
                                if (parseTree.NewStatementDue)
                                {
                                    parseTree.ConsiderStartingNewStatement();
                                }
                                bool flag6 = false;
                                if (parseTree.PathNameMatches(0, "Clause"))
                                {
                                    XmlElement firstNonWhitespaceNonCommentChildElement = parseTree.GetFirstNonWhitespaceNonCommentChildElement(parseTree.CurrentContainer.ParentNode);
                                    bool flag7 = false;
                                    foreach (XmlElement item in parseTree.CurrentContainer.ParentNode.SelectNodes("Clause"))
                                    {
                                        if (ContentStartsWithKeyword(item, "INSERT"))
                                        {
                                            flag7 = true;
                                        }
                                    }
                                    if (flag7)
                                    {
                                        bool flag8 = false;
                                        foreach (XmlElement item2 in parseTree.CurrentContainer.ParentNode.SelectNodes("Clause"))
                                        {
                                            if (ContentStartsWithKeyword(item2, "SELECT"))
                                            {
                                                flag8 = true;
                                            }
                                        }
                                        bool flag9 = false;
                                        foreach (XmlElement item3 in parseTree.CurrentContainer.ParentNode.SelectNodes("Clause"))
                                        {
                                            if (ContentStartsWithKeyword(item3, "VALUES"))
                                            {
                                                flag9 = true;
                                            }
                                        }
                                        bool flag10 = false;
                                        foreach (XmlElement item4 in parseTree.CurrentContainer.ParentNode.SelectNodes("Clause"))
                                        {
                                            if (ContentStartsWithKeyword(item4, "EXEC") || ContentStartsWithKeyword(item4, "EXECUTE"))
                                            {
                                                flag10 = true;
                                            }
                                        }
                                        if (!flag8 && !flag9 && !flag10)
                                        {
                                            flag6 = true;
                                        }
                                    }
                                    XmlElement firstNonWhitespaceNonCommentChildElement2 = parseTree.GetFirstNonWhitespaceNonCommentChildElement(parseTree.CurrentContainer);
                                    if (firstNonWhitespaceNonCommentChildElement2 != null && firstNonWhitespaceNonCommentChildElement2.Name.Equals("SetOperatorClause"))
                                    {
                                        flag6 = true;
                                    }
                                }
                                if (!flag6)
                                {
                                    parseTree.ConsiderStartingNewStatement();
                                }
                                parseTree.ConsiderStartingNewClause();
                                parseTree.SaveNewElement("OtherKeyword", token.Value);
                                break;
                            }
                            if (text.StartsWith("UPDATE "))
                            {
                                if (parseTree.NewStatementDue)
                                {
                                    parseTree.ConsiderStartingNewStatement();
                                }
                                if (!parseTree.PathNameMatches(0, "ContainerContentBody") || !parseTree.PathNameMatches(1, "CursorForOptions"))
                                {
                                    parseTree.ConsiderStartingNewStatement();
                                    parseTree.ConsiderStartingNewClause();
                                }
                                parseTree.SaveNewElement("OtherKeyword", token.Value);
                                break;
                            }
                            if (text.StartsWith("TO "))
                            {
                                if (parseTree.PathNameMatches(0, "ContainerContentBody") && parseTree.PathNameMatches(1, "PermissionsTarget"))
                                {
                                    parseTree.MoveToAncestorContainer(2, "PermissionsBlock");
                                    parseTree.StartNewContainer("PermissionsRecipient", token.Value, "ContainerContentBody");
                                }
                                else
                                {
                                    parseTree.SaveNewElement("OtherKeyword", token.Value);
                                }
                                break;
                            }
                            if (text.StartsWith("FROM "))
                            {
                                if (parseTree.PathNameMatches(0, "ContainerContentBody") && parseTree.PathNameMatches(1, "PermissionsTarget"))
                                {
                                    parseTree.MoveToAncestorContainer(2, "PermissionsBlock");
                                    parseTree.StartNewContainer("PermissionsRecipient", token.Value, "ContainerContentBody");
                                }
                                else
                                {
                                    parseTree.ConsiderStartingNewClause();
                                    parseTree.SaveNewElement("OtherKeyword", token.Value);
                                    parseTree.CurrentContainer = parseTree.SaveNewElement("SelectionTarget", "");
                                }
                                break;
                            }
                            if (text.StartsWith("CASCADE ") && parseTree.PathNameMatches(0, "ContainerContentBody") && parseTree.PathNameMatches(1, "PermissionsRecipient"))
                            {
                                parseTree.MoveToAncestorContainer(2, "PermissionsBlock");
                                parseTree.CurrentContainer = parseTree.SaveNewElement("ContainerContentBody", "", parseTree.SaveNewElement("DDLWith", ""));
                                parseTree.SaveNewElement("OtherKeyword", token.Value);
                                break;
                            }
                            if (text.StartsWith("SET "))
                            {
                                XmlElement firstNonWhitespaceNonCommentChildElement3 = parseTree.GetFirstNonWhitespaceNonCommentChildElement(parseTree.CurrentContainer);
                                if (firstNonWhitespaceNonCommentChildElement3 == null || !firstNonWhitespaceNonCommentChildElement3.Name.Equals("OtherKeyword") || !firstNonWhitespaceNonCommentChildElement3.InnerText.ToUpperInvariant().StartsWith("UPDATE"))
                                {
                                    parseTree.ConsiderStartingNewStatement();
                                }
                                parseTree.ConsiderStartingNewClause();
                                parseTree.SaveNewElement("OtherKeyword", token.Value);
                                break;
                            }
                            if (text.StartsWith("BETWEEN "))
                            {
                                parseTree.CurrentContainer = parseTree.SaveNewElement("Between", "");
                                parseTree.SaveNewElement("OtherKeyword", token.Value, parseTree.SaveNewElement("ContainerOpen", ""));
                                parseTree.CurrentContainer = parseTree.SaveNewElement("LowerBound", "");
                                break;
                            }
                            if (text.StartsWith("AND "))
                            {
                                if (parseTree.PathNameMatches(0, "LowerBound"))
                                {
                                    parseTree.MoveToAncestorContainer(1, "Between");
                                    parseTree.SaveNewElement("OtherKeyword", token.Value, parseTree.SaveNewElement("ContainerClose", ""));
                                    parseTree.CurrentContainer = parseTree.SaveNewElement("UpperBound", "");
                                }
                                else
                                {
                                    parseTree.EscapeAnyBetweenConditions();
                                    parseTree.SaveNewElement("OtherKeyword", token.Value, parseTree.SaveNewElement("And", ""));
                                }
                                break;
                            }
                            if (text.StartsWith("OR "))
                            {
                                parseTree.EscapeAnyBetweenConditions();
                                parseTree.SaveNewElement("OtherKeyword", token.Value, parseTree.SaveNewElement("Or", ""));
                                break;
                            }
                            if (text.StartsWith("WITH "))
                            {
                                if (parseTree.NewStatementDue)
                                {
                                    parseTree.ConsiderStartingNewStatement();
                                }
                                if (parseTree.PathNameMatches(0, "Clause") && parseTree.PathNameMatches(1, "SqlStatement") && !parseTree.HasNonWhiteSpaceNonCommentContent(parseTree.CurrentContainer))
                                {
                                    parseTree.CurrentContainer = parseTree.SaveNewElement("CTEWithClause", "");
                                    parseTree.SaveNewElement("OtherKeyword", token.Value, parseTree.SaveNewElement("ContainerOpen", ""));
                                    parseTree.CurrentContainer = parseTree.SaveNewElement("CTEAlias", "");
                                }
                                else if (parseTree.PathNameMatches(0, "ContainerContentBody") && parseTree.PathNameMatches(1, "PermissionsRecipient"))
                                {
                                    parseTree.MoveToAncestorContainer(2, "PermissionsBlock");
                                    parseTree.StartNewContainer("DDLWith", token.Value, "ContainerContentBody");
                                }
                                else if (parseTree.PathNameMatches(0, "DDLProceduralBlock") || parseTree.PathNameMatches(0, "DDLOtherBlock"))
                                {
                                    parseTree.StartNewContainer("DDLWith", token.Value, "ContainerContentBody");
                                }
                                else if (parseTree.PathNameMatches(0, "SelectionTarget"))
                                {
                                    parseTree.SaveNewElement("OtherKeyword", token.Value);
                                }
                                else
                                {
                                    parseTree.ConsiderStartingNewClause();
                                    parseTree.SaveNewElement("OtherKeyword", token.Value);
                                }
                                break;
                            }
                            if (tokenList.Count > i + 1 && tokenList[i + 1].Type == SqlTokenType.Colon && (tokenList.Count <= i + 2 || tokenList[i + 2].Type != SqlTokenType.Colon))
                            {
                                parseTree.ConsiderStartingNewStatement();
                                parseTree.SaveNewElement("Label", token.Value + tokenList[i + 1].Value);
                                i++;
                                break;
                            }
                            if (IsStatementStarter(token) || parseTree.NewStatementDue)
                            {
                                parseTree.ConsiderStartingNewStatement();
                            }
                            if (IsClauseStarter(token))
                            {
                                parseTree.ConsiderStartingNewClause();
                            }
                            string newElementName = "Other";
                            if (KeywordList.TryGetValue(token.Value, out var value4))
                            {
                                switch (value4)
                                {
                                    case KeywordType.OperatorKeyword:
                                        newElementName = "AlphaOperator";
                                        break;
                                    case KeywordType.FunctionKeyword:
                                        newElementName = "FunctionKeyword";
                                        break;
                                    case KeywordType.DataTypeKeyword:
                                        newElementName = "DataTypeKeyword";
                                        break;
                                    case KeywordType.OtherKeyword:
                                        parseTree.EscapeAnySelectionTarget();
                                        newElementName = "OtherKeyword";
                                        break;
                                    default:
                                        throw new Exception("Unrecognized Keyword Type!");
                                }
                            }
                            parseTree.SaveNewElement(newElementName, token.Value);
                            break;
                        }
                    case SqlTokenType.Semicolon:
                        parseTree.SaveNewElement("Semicolon", token.Value);
                        parseTree.NewStatementDue = true;
                        break;
                    case SqlTokenType.Colon:
                        if (tokenList.Count > i + 1 && tokenList[i + 1].Type == SqlTokenType.Colon)
                        {
                            parseTree.SaveNewElement("ScopeResolutionOperator", token.Value + tokenList[i + 1].Value);
                            i++;
                        }
                        else if (tokenList.Count > i + 1 && tokenList[i + 1].Type == SqlTokenType.OtherNode)
                        {
                            parseTree.SaveNewElement("Other", token.Value + tokenList[i + 1].Value);
                            i++;
                        }
                        else
                        {
                            parseTree.SaveNewElementWithError("OtherOperator", token.Value);
                        }
                        break;
                    case SqlTokenType.Comma:
                        {
                            bool flag12 = parseTree.PathNameMatches(0, "ContainerContentBody") && parseTree.PathNameMatches(1, "CTEWithClause");
                            parseTree.SaveNewElement(GetEquivalentSqlNodeName(token.Type), token.Value);
                            if (flag12)
                            {
                                parseTree.MoveToAncestorContainer(1, "CTEWithClause");
                                parseTree.CurrentContainer = parseTree.SaveNewElement("CTEAlias", "");
                            }
                            break;
                        }
                    case SqlTokenType.EqualsSign:
                        parseTree.SaveNewElement("EqualsSign", token.Value);
                        if (parseTree.PathNameMatches(0, "DDLDeclareBlock"))
                        {
                            parseTree.CurrentContainer = parseTree.SaveNewElement("ContainerContentBody", "");
                        }
                        break;
                    case SqlTokenType.WhiteSpace:
                    case SqlTokenType.SingleLineComment:
                    case SqlTokenType.SingleLineCommentCStyle:
                    case SqlTokenType.MultiLineComment:
                        if (parseTree.PathNameMatches(0, "Clause") && parseTree.PathNameMatches(1, "SqlStatement") && parseTree.CurrentContainer.SelectSingleNode("*") == null)
                        {
                            parseTree.SaveNewElementAsPriorSibling(GetEquivalentSqlNodeName(token.Type), token.Value, parseTree.CurrentContainer);
                        }
                        else
                        {
                            parseTree.SaveNewElement(GetEquivalentSqlNodeName(token.Type), token.Value);
                        }
                        break;
                    case SqlTokenType.String:
                    case SqlTokenType.NationalString:
                    case SqlTokenType.BracketQuotedName:
                    case SqlTokenType.QuotedString:
                    case SqlTokenType.Period:
                    case SqlTokenType.Asterisk:
                    case SqlTokenType.MonetaryValue:
                    case SqlTokenType.Number:
                    case SqlTokenType.BinaryValue:
                    case SqlTokenType.OtherOperator:
                    case SqlTokenType.PseudoName:
                        parseTree.SaveNewElement(GetEquivalentSqlNodeName(token.Type), token.Value);
                        break;
                    default:
                        throw new Exception("Unrecognized element encountered!");
                }
            }
            if (tokenList.HasUnfinishedToken)
            {
                parseTree.SetError();
            }
            if (!parseTree.FindValidBatchEnd())
            {
                parseTree.SetError();
            }
            return parseTree;
        }

        private static bool ContentStartsWithKeyword(XmlElement providedContainer, string contentToMatch)
        {
            ParseTree parseTree = (ParseTree)providedContainer.OwnerDocument;
            XmlElement firstNonWhitespaceNonCommentChildElement = parseTree.GetFirstNonWhitespaceNonCommentChildElement(providedContainer);
           // bool flag = false;
            string text = null;
            if (firstNonWhitespaceNonCommentChildElement != null && firstNonWhitespaceNonCommentChildElement.Name.Equals("OtherKeyword") && firstNonWhitespaceNonCommentChildElement.InnerText != null)
            {
                text = firstNonWhitespaceNonCommentChildElement.InnerText.ToUpperInvariant();
            }
            if (firstNonWhitespaceNonCommentChildElement != null && firstNonWhitespaceNonCommentChildElement.Name.Equals("CompoundKeyword"))
            {
                text = firstNonWhitespaceNonCommentChildElement.GetAttribute("simpleText");
            }
            if (text != null)
            {
                return text.Equals(contentToMatch) || text.StartsWith(contentToMatch + " ");
            }
            return contentToMatch == null;
        }

        private void ProcessCompoundKeywordWithError(ITokenList tokenList, ParseTree sqlTree, XmlElement currentContainerElement, ref int tokenID, List<int> significantTokenPositions, int keywordCount)
        {
            ProcessCompoundKeyword(tokenList, sqlTree, currentContainerElement, ref tokenID, significantTokenPositions, keywordCount);
            sqlTree.SetError();
        }

        private void ProcessCompoundKeyword(ITokenList tokenList, ParseTree sqlTree, XmlElement targetContainer, ref int tokenID, List<int> significantTokenPositions, int keywordCount)
        {
            XmlElement xmlElement = sqlTree.SaveNewElement("CompoundKeyword", "", targetContainer);
            string value = ExtractTokensString(tokenList, significantTokenPositions.GetRange(0, keywordCount)).TrimEnd();
            xmlElement.SetAttribute("simpleText", value);
            AppendNodesWithMapping(sqlTree, tokenList.GetRangeByIndex(significantTokenPositions[0], significantTokenPositions[keywordCount - 1]), "OtherKeyword", xmlElement);
            tokenID = significantTokenPositions[keywordCount - 1];
        }

        private void AppendNodesWithMapping(ParseTree sqlTree, IEnumerable<IToken> tokens, string otherTokenMappingName, XmlElement targetContainer)
        {
            foreach (IToken token in tokens)
            {
                string newElementName = ((token.Type != SqlTokenType.OtherNode) ? GetEquivalentSqlNodeName(token.Type) : otherTokenMappingName);
                sqlTree.SaveNewElement(newElementName, token.Value, targetContainer);
            }
        }

        private string ExtractTokensString(ITokenList tokenList, IList<int> significantTokenPositions)
        {
            StringBuilder stringBuilder = new StringBuilder();
            foreach (int significantTokenPosition in significantTokenPositions)
            {
                if (tokenList[significantTokenPosition].Type == SqlTokenType.Comma)
                {
                    stringBuilder.Append(",");
                }
                else
                {
                    stringBuilder.Append(tokenList[significantTokenPosition].Value.ToUpperInvariant());
                }
                stringBuilder.Append(" ");
            }
            return stringBuilder.ToString();
        }

        private string GetEquivalentSqlNodeName(SqlTokenType tokenType)
        {
            switch (tokenType)
            {
                case SqlTokenType.WhiteSpace:
                    return "WhiteSpace";
                case SqlTokenType.SingleLineComment:
                    return "SingleLineComment";
                case SqlTokenType.SingleLineCommentCStyle:
                    return "SingleLineCommentCStyle";
                case SqlTokenType.MultiLineComment:
                    return "MultiLineComment";
                case SqlTokenType.BracketQuotedName:
                    return "BracketQuotedName";
                case SqlTokenType.Asterisk:
                    return "Asterisk";
                case SqlTokenType.EqualsSign:
                    return "EqualsSign";
                case SqlTokenType.Comma:
                    return "Comma";
                case SqlTokenType.Period:
                    return "Period";
                case SqlTokenType.NationalString:
                    return "NationalString";
                case SqlTokenType.String:
                    return "String";
                case SqlTokenType.QuotedString:
                    return "QuotedString";
                case SqlTokenType.OtherOperator:
                    return "OtherOperator";
                case SqlTokenType.Number:
                    return "NumberValue";
                case SqlTokenType.MonetaryValue:
                    return "MonetaryValue";
                case SqlTokenType.BinaryValue:
                    return "BinaryValue";
                case SqlTokenType.PseudoName:
                    return "PseudoName";
                default:
                    throw new Exception("Mapping not found for provided Token Type");
            }
        }

        private string GetKeywordMatchPhrase(ITokenList tokenList, int tokenID, ref List<string> rawKeywordParts, ref List<int> tokenCounts, ref List<List<IToken>> overflowNodes)
        {
            string text = "";
            int num = 0;
            rawKeywordParts = new List<string>();
            overflowNodes = new List<List<IToken>>();
            tokenCounts = new List<int>();
            string text2 = "";
            int num2 = tokenID;
            while (tokenID < tokenList.Count && num < 7 && (tokenList[tokenID].Type == SqlTokenType.OtherNode || tokenList[tokenID].Type == SqlTokenType.BracketQuotedName || tokenList[tokenID].Type == SqlTokenType.Comma))
            {
                text = text + tokenList[tokenID].Value.ToUpperInvariant() + " ";
                num++;
                rawKeywordParts.Add(text2 + tokenList[tokenID].Value);
                tokenID++;
                tokenCounts.Add(tokenID - num2);
                overflowNodes.Add(new List<IToken>());
                text2 = "";
                while (tokenID < tokenList.Count && (tokenList[tokenID].Type == SqlTokenType.WhiteSpace || tokenList[tokenID].Type == SqlTokenType.SingleLineComment || tokenList[tokenID].Type == SqlTokenType.MultiLineComment))
                {
                    if (tokenList[tokenID].Type == SqlTokenType.WhiteSpace)
                    {
                        text2 += tokenList[tokenID].Value;
                    }
                    else
                    {
                        overflowNodes[num - 1].Add(tokenList[tokenID]);
                    }
                    tokenID++;
                }
            }
            return text;
        }

        private List<int> GetSignificantTokenPositions(ITokenList tokenList, int tokenID, int searchDistance)
        {
            List<int> list = new List<int>();
            int num = tokenID;
            while (tokenID < tokenList.Count && list.Count < searchDistance && (tokenList[tokenID].Type == SqlTokenType.OtherNode || tokenList[tokenID].Type == SqlTokenType.BracketQuotedName || tokenList[tokenID].Type == SqlTokenType.Comma))
            {
                list.Add(tokenID);
                tokenID++;
                while (tokenID < tokenList.Count && (tokenList[tokenID].Type == SqlTokenType.WhiteSpace || tokenList[tokenID].Type == SqlTokenType.SingleLineComment || tokenList[tokenID].Type == SqlTokenType.MultiLineComment))
                {
                    tokenID++;
                }
            }
            return list;
        }

        private XmlElement ProcessCompoundKeyword(ParseTree sqlTree, string newElementName, ref int tokenID, XmlElement currentContainerElement, int compoundKeywordCount, List<int> compoundKeywordTokenCounts, List<string> compoundKeywordRawStrings)
        {
            XmlElement xmlElement = sqlTree.CreateElement(newElementName);
            xmlElement.InnerText = GetCompoundKeyword(ref tokenID, compoundKeywordCount, compoundKeywordTokenCounts, compoundKeywordRawStrings);
            sqlTree.CurrentContainer.AppendChild(xmlElement);
            return xmlElement;
        }

        private string GetCompoundKeyword(ref int tokenID, int compoundKeywordCount, List<int> compoundKeywordTokenCounts, List<string> compoundKeywordRawStrings)
        {
            tokenID += compoundKeywordTokenCounts[compoundKeywordCount - 1] - 1;
            string text = "";
            for (int i = 0; i < compoundKeywordCount; i++)
            {
                text += compoundKeywordRawStrings[i];
            }
            return text;
        }

        private static bool IsStatementStarter(IToken token)
        {
            string text = token.Value.ToUpperInvariant();
            return token.Type == SqlTokenType.OtherNode && (text.Equals("ALTER") || text.Equals("BACKUP") || text.Equals("BREAK") || text.Equals("CLOSE") || text.Equals("CHECKPOINT") || text.Equals("COMMIT") || text.Equals("CONTINUE") || text.Equals("CREATE") || text.Equals("DBCC") || text.Equals("DEALLOCATE") || text.Equals("DELETE") || text.Equals("DECLARE") || text.Equals("DENY") || text.Equals("DROP") || text.Equals("EXEC") || text.Equals("EXECUTE") || text.Equals("FETCH") || text.Equals("GOTO") || text.Equals("GRANT") || text.Equals("IF") || text.Equals("INSERT") || text.Equals("KILL") || text.Equals("MERGE") || text.Equals("OPEN") || text.Equals("PRINT") || text.Equals("RAISERROR") || text.Equals("RECONFIGURE") || text.Equals("RESTORE") || text.Equals("RETURN") || text.Equals("REVERT") || text.Equals("REVOKE") || text.Equals("SELECT") || text.Equals("SET") || text.Equals("SETUSER") || text.Equals("SHUTDOWN") || text.Equals("TRUNCATE") || text.Equals("UPDATE") || text.Equals("USE") || text.Equals("WAITFOR") || text.Equals("WHILE"));
        }

        private static bool IsClauseStarter(IToken token)
        {
            string text = token.Value.ToUpperInvariant();
            return token.Type == SqlTokenType.OtherNode && (text.Equals("DELETE") || text.Equals("EXCEPT") || text.Equals("FOR") || text.Equals("FROM") || text.Equals("GROUP") || text.Equals("HAVING") || text.Equals("INNER") || text.Equals("INTERSECT") || text.Equals("INTO") || text.Equals("INSERT") || text.Equals("MERGE") || text.Equals("ORDER") || text.Equals("OUTPUT") || text.Equals("PIVOT") || text.Equals("RETURNS") || text.Equals("SELECT") || text.Equals("UNION") || text.Equals("UNPIVOT") || text.Equals("UPDATE") || text.Equals("USING") || text.Equals("VALUES") || text.Equals("WHERE") || text.Equals("WITH"));
        }

        private bool IsLatestTokenADDLDetailValue(ParseTree sqlTree)
        {
            for (XmlNode xmlNode = sqlTree.CurrentContainer.LastChild; xmlNode != null; xmlNode = ((!ParseTree.IsCommentOrWhiteSpace(xmlNode.Name)) ? null : xmlNode.PreviousSibling))
            {
                if (xmlNode.Name.Equals("OtherKeyword") || xmlNode.Name.Equals("DataTypeKeyword") || xmlNode.Name.Equals("CompoundKeyword"))
                {
                    string text = null;
                    text = ((!xmlNode.Name.Equals("CompoundKeyword")) ? xmlNode.InnerText.ToUpperInvariant() : xmlNode.Attributes["simpleText"].Value);
                    return text.Equals("NVARCHAR") || text.Equals("VARCHAR") || text.Equals("DECIMAL") || text.Equals("DEC") || text.Equals("NUMERIC") || text.Equals("VARBINARY") || text.Equals("DEFAULT") || text.Equals("IDENTITY") || text.Equals("XML") || text.EndsWith("VARYING") || text.EndsWith("CHAR") || text.EndsWith("CHARACTER") || text.Equals("FLOAT") || text.Equals("DATETIMEOFFSET") || text.Equals("DATETIME2") || text.Equals("TIME");
                }
            }
            return false;
        }

        private bool IsLatestTokenAComma(ParseTree sqlTree)
        {
            for (XmlNode xmlNode = sqlTree.CurrentContainer.LastChild; xmlNode != null; xmlNode = ((!ParseTree.IsCommentOrWhiteSpace(xmlNode.Name)) ? null : xmlNode.PreviousSibling))
            {
                if (xmlNode.Name.Equals("Comma"))
                {
                    return true;
                }
            }
            return false;
        }

        private bool IsLatestTokenAMiscName(XmlElement currentContainerElement)
        {
            for (XmlNode xmlNode = currentContainerElement.LastChild; xmlNode != null; xmlNode = ((!ParseTree.IsCommentOrWhiteSpace(xmlNode.Name)) ? null : xmlNode.PreviousSibling))
            {
                string text = xmlNode.InnerText.ToUpperInvariant();
                if (xmlNode.Name.Equals("BracketQuotedName") || ((xmlNode.Name.Equals("Other") || xmlNode.Name.Equals("FunctionKeyword")) && !text.Equals("AND") && !text.Equals("OR") && !text.Equals("NOT") && !text.Equals("BETWEEN") && !text.Equals("LIKE") && !text.Equals("CONTAINS") && !text.Equals("EXISTS") && !text.Equals("FREETEXT") && !text.Equals("IN") && !text.Equals("ALL") && !text.Equals("SOME") && !text.Equals("ANY") && !text.Equals("FROM") && !text.Equals("JOIN") && !text.EndsWith(" JOIN") && !text.Equals("UNION") && !text.Equals("UNION ALL") && !text.Equals("USING") && !text.Equals("AS") && !text.EndsWith(" APPLY")))
                {
                    return true;
                }
            }
            return false;
        }

        private static bool IsLineBreakingWhiteSpaceOrComment(IToken token)
        {
            return (token.Type == SqlTokenType.WhiteSpace && Regex.IsMatch(token.Value, "(\\r|\\n)+")) || token.Type == SqlTokenType.SingleLineComment;
        }

        private bool IsFollowedByLineBreakingWhiteSpaceOrSingleLineCommentOrEnd(ITokenList tokenList, int tokenID)
        {
            for (int i = tokenID + 1; tokenList.Count >= i + 1; i++)
            {
                if (tokenList[i].Type == SqlTokenType.SingleLineComment)
                {
                    return true;
                }
                if (tokenList[i].Type == SqlTokenType.WhiteSpace)
                {
                    if (Regex.IsMatch(tokenList[i].Value, "(\\r|\\n)+"))
                    {
                        return true;
                    }
                    continue;
                }
                return false;
            }
            return true;
        }

        private static void InitializeKeywordList()
        {
            KeywordList = new Dictionary<string, KeywordType>(StringComparer.OrdinalIgnoreCase);
            KeywordList.Add("@@CONNECTIONS", KeywordType.FunctionKeyword);
            KeywordList.Add("@@CPU_BUSY", KeywordType.FunctionKeyword);
            KeywordList.Add("@@CURSOR_ROWS", KeywordType.FunctionKeyword);
            KeywordList.Add("@@DATEFIRST", KeywordType.FunctionKeyword);
            KeywordList.Add("@@DBTS", KeywordType.FunctionKeyword);
            KeywordList.Add("@@ERROR", KeywordType.FunctionKeyword);
            KeywordList.Add("@@FETCH_STATUS", KeywordType.FunctionKeyword);
            KeywordList.Add("@@IDENTITY", KeywordType.FunctionKeyword);
            KeywordList.Add("@@IDLE", KeywordType.FunctionKeyword);
            KeywordList.Add("@@IO_BUSY", KeywordType.FunctionKeyword);
            KeywordList.Add("@@LANGID", KeywordType.FunctionKeyword);
            KeywordList.Add("@@LANGUAGE", KeywordType.FunctionKeyword);
            KeywordList.Add("@@LOCK_TIMEOUT", KeywordType.FunctionKeyword);
            KeywordList.Add("@@MAX_CONNECTIONS", KeywordType.FunctionKeyword);
            KeywordList.Add("@@MAX_PRECISION", KeywordType.FunctionKeyword);
            KeywordList.Add("@@NESTLEVEL", KeywordType.FunctionKeyword);
            KeywordList.Add("@@OPTIONS", KeywordType.FunctionKeyword);
            KeywordList.Add("@@PACKET_ERRORS", KeywordType.FunctionKeyword);
            KeywordList.Add("@@PACK_RECEIVED", KeywordType.FunctionKeyword);
            KeywordList.Add("@@PACK_SENT", KeywordType.FunctionKeyword);
            KeywordList.Add("@@PROCID", KeywordType.FunctionKeyword);
            KeywordList.Add("@@REMSERVER", KeywordType.FunctionKeyword);
            KeywordList.Add("@@ROWCOUNT", KeywordType.FunctionKeyword);
            KeywordList.Add("@@SERVERNAME", KeywordType.FunctionKeyword);
            KeywordList.Add("@@SERVICENAME", KeywordType.FunctionKeyword);
            KeywordList.Add("@@SPID", KeywordType.FunctionKeyword);
            KeywordList.Add("@@TEXTSIZE", KeywordType.FunctionKeyword);
            KeywordList.Add("@@TIMETICKS", KeywordType.FunctionKeyword);
            KeywordList.Add("@@TOTAL_ERRORS", KeywordType.FunctionKeyword);
            KeywordList.Add("@@TOTAL_READ", KeywordType.FunctionKeyword);
            KeywordList.Add("@@TOTAL_WRITE", KeywordType.FunctionKeyword);
            KeywordList.Add("@@TRANCOUNT", KeywordType.FunctionKeyword);
            KeywordList.Add("@@VERSION", KeywordType.FunctionKeyword);
            KeywordList.Add("ABS", KeywordType.FunctionKeyword);
            KeywordList.Add("ACOS", KeywordType.FunctionKeyword);
            KeywordList.Add("ACTIVATION", KeywordType.OtherKeyword);
            KeywordList.Add("ADD", KeywordType.OtherKeyword);
            KeywordList.Add("ALL", KeywordType.OperatorKeyword);
            KeywordList.Add("ALTER", KeywordType.OtherKeyword);
            KeywordList.Add("AND", KeywordType.OperatorKeyword);
            KeywordList.Add("ANSI_DEFAULTS", KeywordType.OtherKeyword);
            KeywordList.Add("ANSI_NULLS", KeywordType.OtherKeyword);
            KeywordList.Add("ANSI_NULL_DFLT_OFF", KeywordType.OtherKeyword);
            KeywordList.Add("ANSI_NULL_DFLT_ON", KeywordType.OtherKeyword);
            KeywordList.Add("ANSI_PADDING", KeywordType.OtherKeyword);
            KeywordList.Add("ANSI_WARNINGS", KeywordType.OtherKeyword);
            KeywordList.Add("ANY", KeywordType.OperatorKeyword);
            KeywordList.Add("APP_NAME", KeywordType.FunctionKeyword);
            KeywordList.Add("ARITHABORT", KeywordType.OtherKeyword);
            KeywordList.Add("ARITHIGNORE", KeywordType.OtherKeyword);
            KeywordList.Add("AS", KeywordType.OtherKeyword);
            KeywordList.Add("ASC", KeywordType.OtherKeyword);
            KeywordList.Add("ASCII", KeywordType.FunctionKeyword);
            KeywordList.Add("ASIN", KeywordType.FunctionKeyword);
            KeywordList.Add("ATAN", KeywordType.FunctionKeyword);
            KeywordList.Add("ATN2", KeywordType.FunctionKeyword);
            KeywordList.Add("AUTHORIZATION", KeywordType.OtherKeyword);
            KeywordList.Add("AVG", KeywordType.FunctionKeyword);
            KeywordList.Add("BACKUP", KeywordType.OtherKeyword);
            KeywordList.Add("BEGIN", KeywordType.OtherKeyword);
            KeywordList.Add("BETWEEN", KeywordType.OperatorKeyword);
            KeywordList.Add("BIGINT", KeywordType.DataTypeKeyword);
            KeywordList.Add("BINARY", KeywordType.DataTypeKeyword);
            KeywordList.Add("BIT", KeywordType.DataTypeKeyword);
            KeywordList.Add("BREAK", KeywordType.OtherKeyword);
            KeywordList.Add("BROWSE", KeywordType.OtherKeyword);
            KeywordList.Add("BULK", KeywordType.OtherKeyword);
            KeywordList.Add("BY", KeywordType.OtherKeyword);
            KeywordList.Add("CALLER", KeywordType.OtherKeyword);
            KeywordList.Add("CASCADE", KeywordType.OtherKeyword);
            KeywordList.Add("CASE", KeywordType.FunctionKeyword);
            KeywordList.Add("CAST", KeywordType.FunctionKeyword);
            KeywordList.Add("CATALOG", KeywordType.OtherKeyword);
            KeywordList.Add("CEILING", KeywordType.FunctionKeyword);
            KeywordList.Add("CHAR", KeywordType.DataTypeKeyword);
            KeywordList.Add("CHARACTER", KeywordType.DataTypeKeyword);
            KeywordList.Add("CHARINDEX", KeywordType.FunctionKeyword);
            KeywordList.Add("CHECK", KeywordType.OtherKeyword);
            KeywordList.Add("CHECKALLOC", KeywordType.OtherKeyword);
            KeywordList.Add("CHECKCATALOG", KeywordType.OtherKeyword);
            KeywordList.Add("CHECKCONSTRAINTS", KeywordType.OtherKeyword);
            KeywordList.Add("CHECKDB", KeywordType.OtherKeyword);
            KeywordList.Add("CHECKFILEGROUP", KeywordType.OtherKeyword);
            KeywordList.Add("CHECKIDENT", KeywordType.OtherKeyword);
            KeywordList.Add("CHECKPOINT", KeywordType.OtherKeyword);
            KeywordList.Add("CHECKSUM", KeywordType.FunctionKeyword);
            KeywordList.Add("CHECKSUM_AGG", KeywordType.FunctionKeyword);
            KeywordList.Add("CHECKTABLE", KeywordType.OtherKeyword);
            KeywordList.Add("CLEANTABLE", KeywordType.OtherKeyword);
            KeywordList.Add("CLOSE", KeywordType.OtherKeyword);
            KeywordList.Add("CLUSTERED", KeywordType.OtherKeyword);
            KeywordList.Add("COALESCE", KeywordType.FunctionKeyword);
            KeywordList.Add("COLLATIONPROPERTY", KeywordType.FunctionKeyword);
            KeywordList.Add("COLLECTION", KeywordType.OtherKeyword);
            KeywordList.Add("COLUMN", KeywordType.OtherKeyword);
            KeywordList.Add("COLUMNPROPERTY", KeywordType.FunctionKeyword);
            KeywordList.Add("COL_LENGTH", KeywordType.FunctionKeyword);
            KeywordList.Add("COL_NAME", KeywordType.FunctionKeyword);
            KeywordList.Add("COMMIT", KeywordType.OtherKeyword);
            KeywordList.Add("COMMITTED", KeywordType.OtherKeyword);
            KeywordList.Add("COMPUTE", KeywordType.OtherKeyword);
            KeywordList.Add("CONCAT", KeywordType.OtherKeyword);
            KeywordList.Add("CONCAT_NULL_YIELDS_NULL", KeywordType.OtherKeyword);
            KeywordList.Add("CONCURRENCYVIOLATION", KeywordType.OtherKeyword);
            KeywordList.Add("CONFIRM", KeywordType.OtherKeyword);
            KeywordList.Add("CONSTRAINT", KeywordType.OtherKeyword);
            KeywordList.Add("CONTAINS", KeywordType.OtherKeyword);
            KeywordList.Add("CONTAINSTABLE", KeywordType.FunctionKeyword);
            KeywordList.Add("CONTINUE", KeywordType.OtherKeyword);
            KeywordList.Add("CONTROL", KeywordType.OtherKeyword);
            KeywordList.Add("CONTROLROW", KeywordType.OtherKeyword);
            KeywordList.Add("CONVERT", KeywordType.FunctionKeyword);
            KeywordList.Add("COS", KeywordType.FunctionKeyword);
            KeywordList.Add("COT", KeywordType.FunctionKeyword);
            KeywordList.Add("COUNT", KeywordType.FunctionKeyword);
            KeywordList.Add("COUNT_BIG", KeywordType.FunctionKeyword);
            KeywordList.Add("CREATE", KeywordType.OtherKeyword);
            KeywordList.Add("CROSS", KeywordType.OtherKeyword);
            KeywordList.Add("CURRENT", KeywordType.OtherKeyword);
            KeywordList.Add("CURRENT_DATE", KeywordType.OtherKeyword);
            KeywordList.Add("CURRENT_TIME", KeywordType.OtherKeyword);
            KeywordList.Add("CURRENT_TIMESTAMP", KeywordType.FunctionKeyword);
            KeywordList.Add("CURRENT_USER", KeywordType.FunctionKeyword);
            KeywordList.Add("CURSOR", KeywordType.OtherKeyword);
            KeywordList.Add("CURSOR_CLOSE_ON_COMMIT", KeywordType.OtherKeyword);
            KeywordList.Add("CURSOR_STATUS", KeywordType.FunctionKeyword);
            KeywordList.Add("DATABASE", KeywordType.OtherKeyword);
            KeywordList.Add("DATABASEPROPERTY", KeywordType.FunctionKeyword);
            KeywordList.Add("DATABASEPROPERTYEX", KeywordType.FunctionKeyword);
            KeywordList.Add("DATALENGTH", KeywordType.FunctionKeyword);
            KeywordList.Add("DATEADD", KeywordType.FunctionKeyword);
            KeywordList.Add("DATEDIFF", KeywordType.FunctionKeyword);
            KeywordList.Add("DATEFIRST", KeywordType.OtherKeyword);
            KeywordList.Add("DATEFORMAT", KeywordType.OtherKeyword);
            KeywordList.Add("DATENAME", KeywordType.FunctionKeyword);
            KeywordList.Add("DATE", KeywordType.DataTypeKeyword);
            KeywordList.Add("DATEPART", KeywordType.FunctionKeyword);
            KeywordList.Add("DATETIME", KeywordType.DataTypeKeyword);
            KeywordList.Add("DATETIME2", KeywordType.DataTypeKeyword);
            KeywordList.Add("DATETIMEOFFSET", KeywordType.DataTypeKeyword);
            KeywordList.Add("DAY", KeywordType.FunctionKeyword);
            KeywordList.Add("DBCC", KeywordType.OtherKeyword);
            KeywordList.Add("DBREINDEX", KeywordType.OtherKeyword);
            KeywordList.Add("DBREPAIR", KeywordType.OtherKeyword);
            KeywordList.Add("DB_ID", KeywordType.FunctionKeyword);
            KeywordList.Add("DB_NAME", KeywordType.FunctionKeyword);
            KeywordList.Add("DEADLOCK_PRIORITY", KeywordType.OtherKeyword);
            KeywordList.Add("DEALLOCATE", KeywordType.OtherKeyword);
            KeywordList.Add("DEC", KeywordType.DataTypeKeyword);
            KeywordList.Add("DECIMAL", KeywordType.DataTypeKeyword);
            KeywordList.Add("DECLARE", KeywordType.OtherKeyword);
            KeywordList.Add("DEFAULT", KeywordType.OtherKeyword);
            KeywordList.Add("DEFINITION", KeywordType.OtherKeyword);
            KeywordList.Add("DEGREES", KeywordType.FunctionKeyword);
            KeywordList.Add("DELAY", KeywordType.OtherKeyword);
            KeywordList.Add("DELETE", KeywordType.OtherKeyword);
            KeywordList.Add("DENY", KeywordType.OtherKeyword);
            KeywordList.Add("DESC", KeywordType.OtherKeyword);
            KeywordList.Add("DIFFERENCE", KeywordType.FunctionKeyword);
            KeywordList.Add("DISABLE_DEF_CNST_CHK", KeywordType.OtherKeyword);
            KeywordList.Add("DISK", KeywordType.OtherKeyword);
            KeywordList.Add("DISTINCT", KeywordType.OtherKeyword);
            KeywordList.Add("DISTRIBUTED", KeywordType.OtherKeyword);
            KeywordList.Add("DOUBLE", KeywordType.DataTypeKeyword);
            KeywordList.Add("DROP", KeywordType.OtherKeyword);
            KeywordList.Add("DROPCLEANBUFFERS", KeywordType.OtherKeyword);
            KeywordList.Add("DUMMY", KeywordType.OtherKeyword);
            KeywordList.Add("DUMP", KeywordType.OtherKeyword);
            KeywordList.Add("DYNAMIC", KeywordType.OtherKeyword);
            KeywordList.Add("ELSE", KeywordType.OtherKeyword);
            KeywordList.Add("ENCRYPTION", KeywordType.OtherKeyword);
            KeywordList.Add("ERRLVL", KeywordType.OtherKeyword);
            KeywordList.Add("ERROREXIT", KeywordType.OtherKeyword);
            KeywordList.Add("ESCAPE", KeywordType.OtherKeyword);
            KeywordList.Add("EXCEPT", KeywordType.OtherKeyword);
            KeywordList.Add("EXEC", KeywordType.OtherKeyword);
            KeywordList.Add("EXECUTE", KeywordType.OtherKeyword);
            KeywordList.Add("EXISTS", KeywordType.OperatorKeyword);
            KeywordList.Add("EXIT", KeywordType.OtherKeyword);
            KeywordList.Add("EXP", KeywordType.FunctionKeyword);
            KeywordList.Add("EXPAND", KeywordType.OtherKeyword);
            KeywordList.Add("EXTERNAL", KeywordType.OtherKeyword);
            KeywordList.Add("ENDIF", KeywordType.OtherKeyword);
            KeywordList.Add("FAST", KeywordType.OtherKeyword);
            KeywordList.Add("FAST_FORWARD", KeywordType.OtherKeyword);
            KeywordList.Add("FASTFIRSTROW", KeywordType.OtherKeyword);
            KeywordList.Add("FETCH", KeywordType.OtherKeyword);
            KeywordList.Add("FILE", KeywordType.OtherKeyword);
            KeywordList.Add("FILEGROUPPROPERTY", KeywordType.FunctionKeyword);
            KeywordList.Add("FILEGROUP_ID", KeywordType.FunctionKeyword);
            KeywordList.Add("FILEGROUP_NAME", KeywordType.FunctionKeyword);
            KeywordList.Add("FILEPROPERTY", KeywordType.FunctionKeyword);
            KeywordList.Add("FILE_ID", KeywordType.FunctionKeyword);
            KeywordList.Add("FILE_IDEX", KeywordType.FunctionKeyword);
            KeywordList.Add("FILE_NAME", KeywordType.FunctionKeyword);
            KeywordList.Add("FILLFACTOR", KeywordType.OtherKeyword);
            KeywordList.Add("FIPS_FLAGGER", KeywordType.OtherKeyword);
            KeywordList.Add("FLOAT", KeywordType.DataTypeKeyword);
            KeywordList.Add("FLOOR", KeywordType.FunctionKeyword);
            KeywordList.Add("FLOPPY", KeywordType.OtherKeyword);
            KeywordList.Add("FMTONLY", KeywordType.OtherKeyword);
            KeywordList.Add("FOR", KeywordType.OtherKeyword);
            KeywordList.Add("FORCE", KeywordType.OtherKeyword);
            KeywordList.Add("FORCED", KeywordType.OtherKeyword);
            KeywordList.Add("FORCEPLAN", KeywordType.OtherKeyword);
            KeywordList.Add("FOREIGN", KeywordType.OtherKeyword);
            KeywordList.Add("FORMATMESSAGE", KeywordType.FunctionKeyword);
            KeywordList.Add("FORWARD_ONLY", KeywordType.OtherKeyword);
            KeywordList.Add("FREEPROCCACHE", KeywordType.OtherKeyword);
            KeywordList.Add("FREESESSIONCACHE", KeywordType.OtherKeyword);
            KeywordList.Add("FREESYSTEMCACHE", KeywordType.OtherKeyword);
            KeywordList.Add("FREETEXT", KeywordType.OtherKeyword);
            KeywordList.Add("FREETEXTTABLE", KeywordType.FunctionKeyword);
            KeywordList.Add("FROM", KeywordType.OtherKeyword);
            KeywordList.Add("FULL", KeywordType.OtherKeyword);
            KeywordList.Add("FULLTEXT", KeywordType.OtherKeyword);
            KeywordList.Add("FULLTEXTCATALOGPROPERTY", KeywordType.FunctionKeyword);
            KeywordList.Add("FULLTEXTSERVICEPROPERTY", KeywordType.FunctionKeyword);
            KeywordList.Add("FUNCTION", KeywordType.OtherKeyword);
            KeywordList.Add("GEOGRAPHY", KeywordType.DataTypeKeyword);
            KeywordList.Add("GETANCESTOR", KeywordType.FunctionKeyword);
            KeywordList.Add("GETANSINULL", KeywordType.FunctionKeyword);
            KeywordList.Add("GETDATE", KeywordType.FunctionKeyword);
            KeywordList.Add("GETDESCENDANT", KeywordType.FunctionKeyword);
            KeywordList.Add("GETLEVEL", KeywordType.FunctionKeyword);
            KeywordList.Add("GETREPARENTEDVALUE", KeywordType.FunctionKeyword);
            KeywordList.Add("GETROOT", KeywordType.FunctionKeyword);
            KeywordList.Add("GLOBAL", KeywordType.OtherKeyword);
            KeywordList.Add("GO", KeywordType.OtherKeyword);
            KeywordList.Add("GOTO", KeywordType.OtherKeyword);
            KeywordList.Add("GRANT", KeywordType.OtherKeyword);
            KeywordList.Add("GROUP", KeywordType.OtherKeyword);
            KeywordList.Add("GROUPING", KeywordType.FunctionKeyword);
            KeywordList.Add("HASH", KeywordType.OtherKeyword);
            KeywordList.Add("HAVING", KeywordType.OtherKeyword);
            KeywordList.Add("HELP", KeywordType.OtherKeyword);
            KeywordList.Add("HIERARCHYID", KeywordType.DataTypeKeyword);
            KeywordList.Add("HOLDLOCK", KeywordType.OtherKeyword);
            KeywordList.Add("HOST_ID", KeywordType.FunctionKeyword);
            KeywordList.Add("HOST_NAME", KeywordType.FunctionKeyword);
            KeywordList.Add("IDENTITY", KeywordType.FunctionKeyword);
            KeywordList.Add("IDENTITYCOL", KeywordType.OtherKeyword);
            KeywordList.Add("IDENTITY_INSERT", KeywordType.OtherKeyword);
            KeywordList.Add("IDENT_CURRENT", KeywordType.FunctionKeyword);
            KeywordList.Add("IDENT_INCR", KeywordType.FunctionKeyword);
            KeywordList.Add("IDENT_SEED", KeywordType.FunctionKeyword);
            KeywordList.Add("IF", KeywordType.OtherKeyword);
            KeywordList.Add("IGNORE_CONSTRAINTS", KeywordType.OtherKeyword);
            KeywordList.Add("IGNORE_TRIGGERS", KeywordType.OtherKeyword);
            KeywordList.Add("IMAGE", KeywordType.DataTypeKeyword);
            KeywordList.Add("IMPLICIT_TRANSACTIONS", KeywordType.OtherKeyword);
            KeywordList.Add("IN", KeywordType.OperatorKeyword);
            KeywordList.Add("INDEX", KeywordType.OtherKeyword);
            KeywordList.Add("INDEXDEFRAG", KeywordType.OtherKeyword);
            KeywordList.Add("INDEXKEY_PROPERTY", KeywordType.FunctionKeyword);
            KeywordList.Add("INDEXPROPERTY", KeywordType.FunctionKeyword);
            KeywordList.Add("INDEX_COL", KeywordType.FunctionKeyword);
            KeywordList.Add("INNER", KeywordType.OtherKeyword);
            KeywordList.Add("INPUTBUFFER", KeywordType.OtherKeyword);
            KeywordList.Add("INSENSITIVE", KeywordType.DataTypeKeyword);
            KeywordList.Add("INSERT", KeywordType.OtherKeyword);
            KeywordList.Add("INT", KeywordType.DataTypeKeyword);
            KeywordList.Add("INTEGER", KeywordType.DataTypeKeyword);
            KeywordList.Add("INTERSECT", KeywordType.OtherKeyword);
            KeywordList.Add("INTO", KeywordType.OtherKeyword);
            KeywordList.Add("IO", KeywordType.OtherKeyword);
            KeywordList.Add("IS", KeywordType.OtherKeyword);
            KeywordList.Add("ISDATE", KeywordType.FunctionKeyword);
            KeywordList.Add("ISDESCENDANTOF", KeywordType.FunctionKeyword);
            KeywordList.Add("ISNULL", KeywordType.FunctionKeyword);
            KeywordList.Add("ISNUMERIC", KeywordType.FunctionKeyword);
            KeywordList.Add("ISOLATION", KeywordType.OtherKeyword);
            KeywordList.Add("IS_MEMBER", KeywordType.FunctionKeyword);
            KeywordList.Add("IS_SRVROLEMEMBER", KeywordType.FunctionKeyword);
            KeywordList.Add("JOIN", KeywordType.OtherKeyword);
            KeywordList.Add("KEEP", KeywordType.OtherKeyword);
            KeywordList.Add("KEEPDEFAULTS", KeywordType.OtherKeyword);
            KeywordList.Add("KEEPFIXED", KeywordType.OtherKeyword);
            KeywordList.Add("KEEPIDENTITY", KeywordType.OtherKeyword);
            KeywordList.Add("KEY", KeywordType.OtherKeyword);
            KeywordList.Add("KEYSET", KeywordType.OtherKeyword);
            KeywordList.Add("KILL", KeywordType.OtherKeyword);
            KeywordList.Add("LANGUAGE", KeywordType.OtherKeyword);
            KeywordList.Add("LEFT", KeywordType.FunctionKeyword);
            KeywordList.Add("LEN", KeywordType.FunctionKeyword);
            KeywordList.Add("LEVEL", KeywordType.OtherKeyword);
            KeywordList.Add("LIKE", KeywordType.OperatorKeyword);
            KeywordList.Add("LINENO", KeywordType.OtherKeyword);
            KeywordList.Add("LIMIT", KeywordType.OtherKeyword);
            KeywordList.Add("LOAD", KeywordType.OtherKeyword);
            KeywordList.Add("LOCAL", KeywordType.OtherKeyword);
            KeywordList.Add("LOCK_TIMEOUT", KeywordType.OtherKeyword);
            KeywordList.Add("LOG", KeywordType.FunctionKeyword);
            KeywordList.Add("LOG10", KeywordType.FunctionKeyword);
            KeywordList.Add("LOGIN", KeywordType.OtherKeyword);
            KeywordList.Add("LOOP", KeywordType.OtherKeyword);
            KeywordList.Add("LOWER", KeywordType.FunctionKeyword);
            KeywordList.Add("LTRIM", KeywordType.FunctionKeyword);
            KeywordList.Add("MATCHED", KeywordType.OtherKeyword);
            KeywordList.Add("MAX", KeywordType.FunctionKeyword);
            KeywordList.Add("MAX_QUEUE_READERS", KeywordType.OtherKeyword);
            KeywordList.Add("MAXDOP", KeywordType.OtherKeyword);
            KeywordList.Add("MAXRECURSION", KeywordType.OtherKeyword);
            KeywordList.Add("MERGE", KeywordType.OtherKeyword);
            KeywordList.Add("MIN", KeywordType.FunctionKeyword);
            KeywordList.Add("MIRROREXIT", KeywordType.OtherKeyword);
            KeywordList.Add("MODIFY", KeywordType.FunctionKeyword);
            KeywordList.Add("MONEY", KeywordType.DataTypeKeyword);
            KeywordList.Add("MONTH", KeywordType.FunctionKeyword);
            KeywordList.Add("MOVE", KeywordType.OtherKeyword);
            KeywordList.Add("NAME", KeywordType.OtherKeyword);
            KeywordList.Add("NATIONAL", KeywordType.DataTypeKeyword);
            KeywordList.Add("NCHAR", KeywordType.DataTypeKeyword);
            KeywordList.Add("NEWID", KeywordType.FunctionKeyword);
            KeywordList.Add("NEXT", KeywordType.OtherKeyword);
            KeywordList.Add("NOCHECK", KeywordType.OtherKeyword);
            KeywordList.Add("NOCOUNT", KeywordType.OtherKeyword);
            KeywordList.Add("NODES", KeywordType.FunctionKeyword);
            KeywordList.Add("NOEXEC", KeywordType.OtherKeyword);
            KeywordList.Add("NOEXPAND", KeywordType.OtherKeyword);
            KeywordList.Add("NOLOCK", KeywordType.OtherKeyword);
            KeywordList.Add("NONCLUSTERED", KeywordType.OtherKeyword);
            KeywordList.Add("NOT", KeywordType.OperatorKeyword);
            KeywordList.Add("NOWAIT", KeywordType.OtherKeyword);
            KeywordList.Add("NTEXT", KeywordType.DataTypeKeyword);
            KeywordList.Add("NTILE", KeywordType.FunctionKeyword);
            KeywordList.Add("NULL", KeywordType.OtherKeyword);
            KeywordList.Add("NULLIF", KeywordType.FunctionKeyword);
            KeywordList.Add("NUMERIC", KeywordType.DataTypeKeyword);
            KeywordList.Add("NUMERIC_ROUNDABORT", KeywordType.OtherKeyword);
            KeywordList.Add("NVARCHAR", KeywordType.DataTypeKeyword);
            KeywordList.Add("OBJECTPROPERTY", KeywordType.FunctionKeyword);
            KeywordList.Add("OBJECTPROPERTYEX", KeywordType.FunctionKeyword);
            KeywordList.Add("OBJECT", KeywordType.OtherKeyword);
            KeywordList.Add("OBJECT_ID", KeywordType.FunctionKeyword);
            KeywordList.Add("OBJECT_NAME", KeywordType.FunctionKeyword);
            KeywordList.Add("OF", KeywordType.OtherKeyword);
            KeywordList.Add("OFF", KeywordType.OtherKeyword);
            KeywordList.Add("OFFSETS", KeywordType.OtherKeyword);
            KeywordList.Add("ON", KeywordType.OtherKeyword);
            KeywordList.Add("ONCE", KeywordType.OtherKeyword);
            KeywordList.Add("ONLY", KeywordType.OtherKeyword);
            KeywordList.Add("OPEN", KeywordType.OtherKeyword);
            KeywordList.Add("OPENDATASOURCE", KeywordType.OtherKeyword);
            KeywordList.Add("OPENQUERY", KeywordType.FunctionKeyword);
            KeywordList.Add("OPENROWSET", KeywordType.FunctionKeyword);
            KeywordList.Add("OPENTRAN", KeywordType.OtherKeyword);
            KeywordList.Add("OPTIMIZE", KeywordType.OtherKeyword);
            KeywordList.Add("OPTIMISTIC", KeywordType.OtherKeyword);
            KeywordList.Add("OPTION", KeywordType.OtherKeyword);
            KeywordList.Add("OR", KeywordType.OperatorKeyword);
            KeywordList.Add("ORDER", KeywordType.OtherKeyword);
            KeywordList.Add("OUTER", KeywordType.OtherKeyword);
            KeywordList.Add("OUT", KeywordType.OtherKeyword);
            KeywordList.Add("OUTPUT", KeywordType.OtherKeyword);
            KeywordList.Add("OUTPUTBUFFER", KeywordType.OtherKeyword);
            KeywordList.Add("OVER", KeywordType.OtherKeyword);
            KeywordList.Add("OWNER", KeywordType.OtherKeyword);
            KeywordList.Add("PAGLOCK", KeywordType.OtherKeyword);
            KeywordList.Add("PARAMETERIZATION", KeywordType.OtherKeyword);
            KeywordList.Add("PARSE", KeywordType.FunctionKeyword);
            KeywordList.Add("PARSENAME", KeywordType.FunctionKeyword);
            KeywordList.Add("PARSEONLY", KeywordType.OtherKeyword);
            KeywordList.Add("PARTITION", KeywordType.OtherKeyword);
            KeywordList.Add("PATINDEX", KeywordType.FunctionKeyword);
            KeywordList.Add("PERCENT", KeywordType.OtherKeyword);
            KeywordList.Add("PERM", KeywordType.OtherKeyword);
            KeywordList.Add("PERMANENT", KeywordType.OtherKeyword);
            KeywordList.Add("PERMISSIONS", KeywordType.FunctionKeyword);
            KeywordList.Add("PI", KeywordType.FunctionKeyword);
            KeywordList.Add("PINTABLE", KeywordType.OtherKeyword);
            KeywordList.Add("PIPE", KeywordType.OtherKeyword);
            KeywordList.Add("PLAN", KeywordType.OtherKeyword);
            KeywordList.Add("POWER", KeywordType.FunctionKeyword);
            KeywordList.Add("PREPARE", KeywordType.OtherKeyword);
            KeywordList.Add("PRIMARY", KeywordType.OtherKeyword);
            KeywordList.Add("PRINT", KeywordType.OtherKeyword);
            KeywordList.Add("PRIVILEGES", KeywordType.OtherKeyword);
            KeywordList.Add("PROC", KeywordType.OtherKeyword);
            KeywordList.Add("PROCCACHE", KeywordType.OtherKeyword);
            KeywordList.Add("PROCEDURE", KeywordType.OtherKeyword);
            KeywordList.Add("PROCEDURE_NAME", KeywordType.OtherKeyword);
            KeywordList.Add("PROCESSEXIT", KeywordType.OtherKeyword);
            KeywordList.Add("PROCID", KeywordType.OtherKeyword);
            KeywordList.Add("PROFILE", KeywordType.OtherKeyword);
            KeywordList.Add("PUBLIC", KeywordType.OtherKeyword);
            KeywordList.Add("QUERY", KeywordType.FunctionKeyword);
            KeywordList.Add("QUERY_GOVERNOR_COST_LIMIT", KeywordType.OtherKeyword);
            KeywordList.Add("QUEUE", KeywordType.OtherKeyword);
            KeywordList.Add("QUOTED_IDENTIFIER", KeywordType.OtherKeyword);
            KeywordList.Add("QUOTENAME", KeywordType.FunctionKeyword);
            KeywordList.Add("RADIANS", KeywordType.FunctionKeyword);
            KeywordList.Add("RAISERROR", KeywordType.OtherKeyword);
            KeywordList.Add("RAND", KeywordType.FunctionKeyword);
            KeywordList.Add("READ", KeywordType.OtherKeyword);
            KeywordList.Add("READCOMMITTED", KeywordType.OtherKeyword);
            KeywordList.Add("READCOMMITTEDLOCK", KeywordType.OtherKeyword);
            KeywordList.Add("READPAST", KeywordType.OtherKeyword);
            KeywordList.Add("READTEXT", KeywordType.OtherKeyword);
            KeywordList.Add("READUNCOMMITTED", KeywordType.OtherKeyword);
            KeywordList.Add("READ_ONLY", KeywordType.OtherKeyword);
            KeywordList.Add("REAL", KeywordType.DataTypeKeyword);
            KeywordList.Add("RECOMPILE", KeywordType.OtherKeyword);
            KeywordList.Add("RECONFIGURE", KeywordType.OtherKeyword);
            KeywordList.Add("REFERENCES", KeywordType.OtherKeyword);
            KeywordList.Add("REMOTE_PROC_TRANSACTIONS", KeywordType.OtherKeyword);
            KeywordList.Add("REPEATABLE", KeywordType.OtherKeyword);
            KeywordList.Add("REPEATABLEREAD", KeywordType.OtherKeyword);
            KeywordList.Add("REPLACE", KeywordType.FunctionKeyword);
            KeywordList.Add("REPLICATE", KeywordType.FunctionKeyword);
            KeywordList.Add("REPLICATION", KeywordType.OtherKeyword);
            KeywordList.Add("RESTORE", KeywordType.OtherKeyword);
            KeywordList.Add("RESTRICT", KeywordType.OtherKeyword);
            KeywordList.Add("RETURN", KeywordType.OtherKeyword);
            KeywordList.Add("RETURNS", KeywordType.OtherKeyword);
            KeywordList.Add("REVERSE", KeywordType.FunctionKeyword);
            KeywordList.Add("REVERT", KeywordType.OtherKeyword);
            KeywordList.Add("REVOKE", KeywordType.OtherKeyword);
            KeywordList.Add("RIGHT", KeywordType.FunctionKeyword);
            KeywordList.Add("ROBUST", KeywordType.OtherKeyword);
            KeywordList.Add("ROLE", KeywordType.OtherKeyword);
            KeywordList.Add("ROLLBACK", KeywordType.OtherKeyword);
            KeywordList.Add("ROUND", KeywordType.FunctionKeyword);
            KeywordList.Add("ROWCOUNT", KeywordType.OtherKeyword);
            KeywordList.Add("ROWGUIDCOL", KeywordType.OtherKeyword);
            KeywordList.Add("ROWLOCK", KeywordType.OtherKeyword);
            KeywordList.Add("ROWVERSION", KeywordType.DataTypeKeyword);
            KeywordList.Add("RTRIM", KeywordType.FunctionKeyword);
            KeywordList.Add("RULE", KeywordType.OtherKeyword);
            KeywordList.Add("SAVE", KeywordType.OtherKeyword);
            KeywordList.Add("SCHEMA", KeywordType.OtherKeyword);
            KeywordList.Add("SCHEMA_ID", KeywordType.FunctionKeyword);
            KeywordList.Add("SCHEMA_NAME", KeywordType.FunctionKeyword);
            KeywordList.Add("SCOPE_IDENTITY", KeywordType.FunctionKeyword);
            KeywordList.Add("SCROLL", KeywordType.OtherKeyword);
            KeywordList.Add("SCROLL_LOCKS", KeywordType.OtherKeyword);
            KeywordList.Add("SELECT", KeywordType.OtherKeyword);
            KeywordList.Add("SELF", KeywordType.OtherKeyword);
            KeywordList.Add("SERIALIZABLE", KeywordType.OtherKeyword);
            KeywordList.Add("SERVER", KeywordType.OtherKeyword);
            KeywordList.Add("SERVERPROPERTY", KeywordType.FunctionKeyword);
            KeywordList.Add("SESSIONPROPERTY", KeywordType.FunctionKeyword);
            KeywordList.Add("SESSION_USER", KeywordType.FunctionKeyword);
            KeywordList.Add("SET", KeywordType.OtherKeyword);
            KeywordList.Add("SETUSER", KeywordType.OtherKeyword);
            KeywordList.Add("SHOWCONTIG", KeywordType.OtherKeyword);
            KeywordList.Add("SHOWPLAN_ALL", KeywordType.OtherKeyword);
            KeywordList.Add("SHOWPLAN_TEXT", KeywordType.OtherKeyword);
            KeywordList.Add("SHOW_STATISTICS", KeywordType.OtherKeyword);
            KeywordList.Add("SHRINKDATABASE", KeywordType.OtherKeyword);
            KeywordList.Add("SHRINKFILE", KeywordType.OtherKeyword);
            KeywordList.Add("SHUTDOWN", KeywordType.OtherKeyword);
            KeywordList.Add("SIGN", KeywordType.FunctionKeyword);
            KeywordList.Add("SIMPLE", KeywordType.OtherKeyword);
            KeywordList.Add("SIN", KeywordType.FunctionKeyword);
            KeywordList.Add("SMALLDATETIME", KeywordType.DataTypeKeyword);
            KeywordList.Add("SMALLINT", KeywordType.DataTypeKeyword);
            KeywordList.Add("SMALLMONEY", KeywordType.DataTypeKeyword);
            KeywordList.Add("SOME", KeywordType.OperatorKeyword);
            KeywordList.Add("SOUNDEX", KeywordType.FunctionKeyword);
            KeywordList.Add("SPACE", KeywordType.FunctionKeyword);
            KeywordList.Add("SQLPERF", KeywordType.OtherKeyword);
            KeywordList.Add("SQL_VARIANT", KeywordType.DataTypeKeyword);
            KeywordList.Add("SQL_VARIANT_PROPERTY", KeywordType.FunctionKeyword);
            KeywordList.Add("SQRT", KeywordType.FunctionKeyword);
            KeywordList.Add("SQUARE", KeywordType.FunctionKeyword);
            KeywordList.Add("STATE", KeywordType.OtherKeyword);
            KeywordList.Add("STATISTICS", KeywordType.OtherKeyword);
            KeywordList.Add("STATIC", KeywordType.OtherKeyword);
            KeywordList.Add("STATS_DATE", KeywordType.FunctionKeyword);
            KeywordList.Add("STATUS", KeywordType.OtherKeyword);
            KeywordList.Add("STDEV", KeywordType.FunctionKeyword);
            KeywordList.Add("STDEVP", KeywordType.FunctionKeyword);
            KeywordList.Add("STOPLIST", KeywordType.OtherKeyword);
            KeywordList.Add("STR", KeywordType.FunctionKeyword);
            KeywordList.Add("STUFF", KeywordType.FunctionKeyword);
            KeywordList.Add("SUBSTRING", KeywordType.FunctionKeyword);
            KeywordList.Add("SUM", KeywordType.FunctionKeyword);
            KeywordList.Add("SUSER_ID", KeywordType.FunctionKeyword);
            KeywordList.Add("SUSER_NAME", KeywordType.FunctionKeyword);
            KeywordList.Add("SUSER_SID", KeywordType.FunctionKeyword);
            KeywordList.Add("SUSER_SNAME", KeywordType.FunctionKeyword);
            KeywordList.Add("SYNONYM", KeywordType.OtherKeyword);
            KeywordList.Add("SYSNAME", KeywordType.DataTypeKeyword);
            KeywordList.Add("SYSTEM_USER", KeywordType.FunctionKeyword);
            KeywordList.Add("TABLE", KeywordType.OtherKeyword);
            KeywordList.Add("TABLOCK", KeywordType.OtherKeyword);
            KeywordList.Add("TABLOCKX", KeywordType.OtherKeyword);
            KeywordList.Add("TAN", KeywordType.FunctionKeyword);
            KeywordList.Add("TAPE", KeywordType.OtherKeyword);
            KeywordList.Add("TEMP", KeywordType.OtherKeyword);
            KeywordList.Add("TEMPORARY", KeywordType.OtherKeyword);
            KeywordList.Add("TEXT", KeywordType.DataTypeKeyword);
            KeywordList.Add("TEXTPTR", KeywordType.FunctionKeyword);
            KeywordList.Add("TEXTSIZE", KeywordType.OtherKeyword);
            KeywordList.Add("TEXTVALID", KeywordType.FunctionKeyword);
            KeywordList.Add("THEN", KeywordType.OtherKeyword);
            KeywordList.Add("TIME", KeywordType.DataTypeKeyword);
            KeywordList.Add("TIMESTAMP", KeywordType.DataTypeKeyword);
            KeywordList.Add("TINYINT", KeywordType.DataTypeKeyword);
            KeywordList.Add("TO", KeywordType.OtherKeyword);
            KeywordList.Add("TOP", KeywordType.OtherKeyword);
            KeywordList.Add("TOSTRING", KeywordType.FunctionKeyword);
            KeywordList.Add("TRACEOFF", KeywordType.OtherKeyword);
            KeywordList.Add("TRACEON", KeywordType.OtherKeyword);
            KeywordList.Add("TRACESTATUS", KeywordType.OtherKeyword);
            KeywordList.Add("TRAN", KeywordType.OtherKeyword);
            KeywordList.Add("TRANSACTION", KeywordType.OtherKeyword);
            KeywordList.Add("TRIGGER", KeywordType.OtherKeyword);
            KeywordList.Add("TRUNCATE", KeywordType.OtherKeyword);
            KeywordList.Add("TSEQUAL", KeywordType.OtherKeyword);
            KeywordList.Add("TYPEPROPERTY", KeywordType.FunctionKeyword);
            KeywordList.Add("TYPE_ID", KeywordType.FunctionKeyword);
            KeywordList.Add("TYPE_NAME", KeywordType.FunctionKeyword);
            KeywordList.Add("TYPE_WARNING", KeywordType.OtherKeyword);
            KeywordList.Add("UNCOMMITTED", KeywordType.OtherKeyword);
            KeywordList.Add("UNICODE", KeywordType.FunctionKeyword);
            KeywordList.Add("UNION", KeywordType.OtherKeyword);
            KeywordList.Add("UNIQUE", KeywordType.OtherKeyword);
            KeywordList.Add("UNIQUEIDENTIFIER", KeywordType.DataTypeKeyword);
            KeywordList.Add("UNKNOWN", KeywordType.OtherKeyword);
            KeywordList.Add("UNPINTABLE", KeywordType.OtherKeyword);
            KeywordList.Add("UPDATE", KeywordType.OtherKeyword);
            KeywordList.Add("UPDATETEXT", KeywordType.OtherKeyword);
            KeywordList.Add("UPDATEUSAGE", KeywordType.OtherKeyword);
            KeywordList.Add("UPDLOCK", KeywordType.OtherKeyword);
            KeywordList.Add("UPPER", KeywordType.FunctionKeyword);
            KeywordList.Add("INSTR", KeywordType.FunctionKeyword);
            KeywordList.Add("USE", KeywordType.OtherKeyword);
            KeywordList.Add("USER", KeywordType.FunctionKeyword);
            KeywordList.Add("USEROPTIONS", KeywordType.OtherKeyword);
            KeywordList.Add("USER_ID", KeywordType.FunctionKeyword);
            KeywordList.Add("USER_NAME", KeywordType.FunctionKeyword);
            KeywordList.Add("USING", KeywordType.OtherKeyword);
            KeywordList.Add("VALUE", KeywordType.FunctionKeyword);
            KeywordList.Add("VALUES", KeywordType.OtherKeyword);
            KeywordList.Add("VAR", KeywordType.FunctionKeyword);
            KeywordList.Add("VARBINARY", KeywordType.DataTypeKeyword);
            KeywordList.Add("VARCHAR", KeywordType.DataTypeKeyword);
            KeywordList.Add("VARP", KeywordType.FunctionKeyword);
            KeywordList.Add("VARYING", KeywordType.OtherKeyword);
            KeywordList.Add("VIEW", KeywordType.OtherKeyword);
            KeywordList.Add("VIEWS", KeywordType.OtherKeyword);
            KeywordList.Add("WAITFOR", KeywordType.OtherKeyword);
            KeywordList.Add("WHEN", KeywordType.OtherKeyword);
            KeywordList.Add("WHERE", KeywordType.OtherKeyword);
            KeywordList.Add("DBMS_LOB", KeywordType.OtherKeyword);
            KeywordList.Add("WHILE", KeywordType.OtherKeyword);
            KeywordList.Add("WITH", KeywordType.OtherKeyword);
            KeywordList.Add("WORK", KeywordType.OtherKeyword);
            KeywordList.Add("WRITE", KeywordType.FunctionKeyword);
            KeywordList.Add("WRITETEXT", KeywordType.OtherKeyword);
            KeywordList.Add("XACT_ABORT", KeywordType.OtherKeyword);
            KeywordList.Add("XLOCK", KeywordType.OtherKeyword);
            KeywordList.Add("XML", KeywordType.DataTypeKeyword);
            KeywordList.Add("YEAR", KeywordType.FunctionKeyword);
        }
    }
}
